Rust smart contracts for Agentis built with the Odra Framework v2.4.0 on the Casper Network.
-
Rust (latest stable toolchain)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh rustup update stable
-
wasm32 target (required for Casper contracts)
rustup target add wasm32-unknown-unknown
-
WASM tools (binaryen & wabt for optimization)
# Run from project root ./setup.sh # Add to PATH (printed by script) export PATH="$(pwd)/tools/binaryen/bin:$(pwd)/tools/wabt/bin:$PATH"
-
Casper Client (optional, for manual deployments)
cargo install casper-client
| Contract | File | Description |
|---|---|---|
| AgentNFT | src/agent_nft.rs |
CEP-78 NFT for agent identity, metadata, and leveling |
| AgentMarketplace | src/agent_marketplace.rs |
Trustless escrow for agent trading |
| AgentCredits | src/agent_credits.rs |
CEP-18 fungible tokens for session credits |
| RevenueShare | src/revenue_share.rs |
Automated 80/20 revenue splitting |
Build all contracts to WASM:
cargo odra buildOutput files are generated in wasm/ directory.
Run the test suite:
cargo odra testFor verbose output:
cargo odra test -- --nocaptureFor local testing with the Odra mock VM:
cargo run --bin deploy_local --features localDeploy to Casper Testnet:
-
Create environment file:
cp .env.example .env
Edit
.envwith your values:ODRA_CASPER_LIVENET_NODE_ADDRESS=https://node.testnet.casper.network/rpc ODRA_CASPER_LIVENET_CHAIN_NAME=casper-test ODRA_CASPER_LIVENET_SECRET_KEY_PATH=./keys/secret_key.pem ODRA_CASPER_LIVENET_EVENTS_URL=https://node.testnet.casper.network/events/main
-
Generate keys (if you don't have them):
casper-client keygen ./keys
-
Fund your account with testnet CSPR from the faucet
-
Run deployment:
cargo run --bin deploy_testnet --features livenet
-
Save the output — the script prints deployed contract hashes needed for frontend configuration.
After deployment, update the frontend src/constants/contracts.ts with your contract package hashes:
export const CONTRACTS = {
network: "testnet",
chainName: "casper-test",
rpcUrl: "https://node.testnet.casper.network/rpc",
addresses: {
AgentNFT: "your-package-hash-here",
AgentMarketplace: "your-package-hash-here",
AgentCredits: "your-package-hash-here",
RevenueShare: "your-package-hash-here",
},
} as const;| Binary | Feature | Description |
|---|---|---|
deploy_local |
local |
Deploy to OdraMock for testing |
deploy_testnet |
livenet |
Deploy to Casper Testnet/Mainnet |
ai_nft_casper_cli |
— | CLI for contract interactions |
ai_nft_casper_build_contract |
— | Build WASM binaries |
ai_nft_casper_build_schema |
— | Generate contract schemas |
After deploying all contracts, configure inter-contract references:
-
Set RevenueShare on AgentCredits:
casper-client put-deploy \ --node-address $CASPER_NODE_URL \ --chain-name $CASPER_CHAIN_NAME \ --secret-key $CASPER_SECRET_KEY \ --payment-amount 1000000000 \ --session-hash $CREDITS_CONTRACT_HASH \ --session-entry-point "set_revenue_share_contract" \ --session-arg "new_contract:key='$REVENUE_SHARE_CONTRACT_HASH'"
-
Set AgentNFT on RevenueShare:
casper-client put-deploy \ --node-address $CASPER_NODE_URL \ --chain-name $CASPER_CHAIN_NAME \ --secret-key $CASPER_SECRET_KEY \ --payment-amount 1000000000 \ --session-hash $REVENUE_SHARE_CONTRACT_HASH \ --session-entry-point "set_agent_nft" \ --session-arg "new_agent_nft:key='$NFT_CONTRACT_HASH'"
-
Set Authorized Spender (backend wallet for credit operations):
casper-client put-deploy \ --node-address $CASPER_NODE_URL \ --chain-name $CASPER_CHAIN_NAME \ --secret-key $CASPER_SECRET_KEY \ --payment-amount 1000000000 \ --session-hash $CREDITS_CONTRACT_HASH \ --session-entry-point "set_authorized_spender" \ --session-arg "spender:key='account-hash-$BACKEND_ACCOUNT_HASH'" \ --session-arg "authorized:bool='true'"
contract/
├── src/
│ ├── lib.rs # Module exports
│ ├── agent_nft.rs # NFT contract
│ ├── agent_marketplace.rs # Trading contract
│ ├── agent_credits.rs # Credits contract
│ ├── revenue_share.rs # Revenue routing
│ └── tests.rs # Unit tests
├── bin/
│ ├── build_contract.rs # WASM build script
│ ├── build_schema.rs # Schema generator
│ ├── cli.rs # CLI interface
│ ├── deploy_local.rs # Local deployment
│ └── deploy_testnet.rs # Testnet deployment
├── Cargo.toml # Dependencies
└── Odra.toml # Contract definitions