Skip to main content

Prerequisites

  • Rust installed with WASM target
  • NEXUS CLI installed
  • A funded wallet

Step 1: Create Project

nexus dev scaffold my_contract --template basic
cd my_contract

Step 2: Write Contract

Edit src/lib.rs:
use nexus_sdk::{
    solidity::*,
    contract_api::ez::ret,
};

// State variables
static INITIALIZED: Mapping<&[u8], bool> = Mapping::new(b"init");
static OWNER: Mapping<&[u8], Address> = Mapping::new(b"owner");

nexus_fn! {
    fn init() {
        let sender = Blockchain::msg.sender();
        OWNER.set(&b"val".as_slice(), sender);
        INITIALIZED.set(&b"val".as_slice(), true);
        ret::u32(1)
    }
}

nexus_fn! {
    fn greet() {
        ret::string("Hello, NEXUS!")
    }
}

Step 3: Compile

cargo build --target wasm32-unknown-unknown --release

Step 4: Validate

nexus dev validate ./target/wasm32-unknown-unknown/release/my_contract.wasm

Step 5: Create Wallet

nexus wallet new deployer

Step 6: Fund Wallet

Get testnet funds from the faucet or deposit to your vault address.

Step 7: Deploy

nexus contract deploy \
  --wasm ./target/wasm32-unknown-unknown/release/my_contract.wasm \
  --name my_contract \
  --from deployer

Step 8: Interact

nexus contract call \
  --contract <CONTRACT_ID> \
  --function greet \
  --from deployer

Next Steps

  • Add more functions
  • Emit events
  • Integrate with frontend