This repository uses the recommended structure for a Soroban project:
.
├── contracts
│ └── hello_world
│ ├── src
│ │ ├── lib.rs
│ │ └── test.rs
│ └── Cargo.toml
├── Cargo.toml
└── README.md
- New Soroban contracts can be put in
contracts, each in their own directory. There is already ahello_worldcontract in there to get you started. - If you initialized this project with any other example contracts via
--with-example, those contracts will be in thecontractsdirectory as well. - Contracts should have their own
Cargo.tomlfiles that rely on the top-levelCargo.tomlworkspace for their dependencies. - Frontend libraries can be added to the top-level directory as well. If you initialized this project with a frontend template via
--frontend-templateyou will have those files already included.
When you deploy a smart contract to a network, you need to specify an identity that will be used to sign the transactions.
Let's configure an identity called alice. You can use any name you want, but it might be nice to have some named identities that you can use for testing, such as alice, bob, and carol. Notice that the account will be funded using Friendbot.
stellar keys generate --global alice --network testnet --fundYou can see the public key of alice with:
stellar keys address aliceTo deploy the contract to the Stellar testnet, use the following command:
stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/hello_world.wasm \
--source alice \
--network testnetMake sure you have:
- Built the contract using
cargo build --target wasm32-unknown-unknown --release - Set up your Stellar account credentials
- Have sufficient testnet funds in your account
After deployment, you can invoke the contract's hello function using:
stellar contract invoke \
--id CACDYF3CYMJEJTIVFESQYZTN67GO2R5D5IUABTCUG3HXQSRXCSOROBAN \
--source alice \
--network testnet \
-- \
hello \
--to RPCReplace the contract ID with the one you received during deployment.