Install WebAssembly (Wasm) bytecode using code
This process uploads the contract code to the Stellar Testnet in a transaction, the uploaded Wasm blob is a contract source, which can be thought of as a ‘class’ of a contract. Multiple instances of a contract can be deployed which share the same source, but have their own state.Prerequisites
Before you begin, ensure you have the following installed to compile a smart contract:- Rust and Cargo (for compiling smart contracts)
- The Stellar CLI
Initialize and build a sample Rust contract
hello_world contract in soroban_examples to the directory hello-world. You may use the -w option to create with another example like account.
After building the contract for release, the generated .wasm file is at the path hello-word/target/wasm32v1-none/release/hello_world.wasm
Upload Wasm to the Stellar blockchain
We can use one of the client SDKs, install necessary dependencies for your chosen programming language: Create a new directory for your project and navigate into it:Running the install script
Different programming languages can be used to upload the.wasm file, its SHA256 hash is used for deploying the contract.
- JavaScript
- Python
- Rust
This guide will walk you through installing the Wasm of the contract using the JavaScript SDK: js-stellar-sdk.Create a new Node.js project with a JavaScript file, and install necessary dependencies:Run the script with
node index.js, it reads the Wasm file, gets account details, and uploads the contract in a transaction:"Your_Secret_Key" with your actual secret key.
hello, and show its secret key.