markdownBackend Architecture

The platform relies on two separate backend services for contract compilation. Rust contracts are compiled via a backend service at near-by-example-backend.fly.dev, while JavaScript/TypeScript contracts use learn-near-backend.fly.dev. When a user clicks "Run", the frontend sends a POST request to the appropriate compilation endpoint with the contract code and language specification.

The compilation process works as follows: the backend receives the source code, sets up a temporary compilation environment, and uses either near-sdk-js for JavaScript contracts or Rust toolchain for Rust contracts. The backend compiles the code to WebAssembly (WASM), validates the output, and returns a base64-encoded WASM binary along with compilation metadata (size, compilation time, success status). If compilation fails, detailed error messages are extracted from stderr and returned to the frontend, which displays them in the console panel.

Deployment Mechanisms

The platform supports two deployment methods depending on configuration. The primary method uses backend NEAR CLI deployment, which doesn't require wallet connection. When a user clicks "Deploy", the frontend first compiles the contract (if not already compiled), then sends the WASM binary to the deployment backend at near-by-example-backend.fly.dev/api/deploy. The backend uses NEAR CLI with pre-configured credentials to create a new contract account, deploy the WASM, and initialize the contract with default parameters. This method is seamless but requires backend configuration with NEAR_ACCOUNT_ID and NEAR_PRIVATE_KEY environment variables.

Alternatively, for JavaScript contracts, the platform can use wallet-based deployment through MyNearWallet. This method requires users to connect their wallet, and the deployment transaction is signed and sent through the wallet interface. The wallet redirects users to MyNearWallet's website for transaction approval, then redirects back with transaction hashes in the URL parameters. The frontend detects these parameters and redirects to a success page showing deployment details.

Last updated

Was this helpful?