Skip to main content

nexus dev validate

Validate a WASM contract file.
nexus dev validate <WASM_PATH>

Example

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

Output (Valid)

→ Validating WASM contract...
✓ Contract is valid!

Stats:
  Functions: 12
  Imports: 8
  Exports: 5
  Code size: 45678 bytes

Output (Invalid)

→ Validating WASM contract...
✗ Contract validation failed!
  • Missing required export: init
  • Invalid import: env.forbidden_function

⚠ Warnings:
  • Large code size (>100KB)
  • Unused function detected

nexus dev compile

Compile a Rust contract to WASM.
nexus dev compile <SOURCE_DIR> --output <OUTPUT_FILE>

Options

OptionRequiredDescription
-o, --output <FILE>YesOutput WASM file path

Example

nexus dev compile ./my_contract --output ./my_contract.wasm

Output

→ Compiling contract...
Source: ./my_contract
Output: ./my_contract.wasm
This command invokes cargo build --target wasm32-unknown-unknown --release internally.

nexus dev scaffold

Create a new smart contract project from a template.
nexus dev scaffold <NAME> [OPTIONS]

Options

OptionDefaultDescription
-t, --template <TYPE>basicTemplate type
-p, --path <DIR>.Output directory

Templates

TemplateDescription
basicMinimal contract with init and handle
ownableContract with owner management
pausableContract with pause/unpause functionality
nep20NEP-20 fungible token

Examples

# Basic contract
nexus dev scaffold my_contract

# NEP-20 token
nexus dev scaffold my_token --template nep20

# In specific directory
nexus dev scaffold my_contract --path ./contracts

Output

→ Scaffolding contract...
Name: my_contract
Template: basic
Path: .
✓ Project created at ./my_contract

Generated Structure

my_contract/
├── Cargo.toml
└── src/
    └── lib.rs

nexus dev node

Start a local development node.
nexus dev node [OPTIONS]

Options

OptionDefaultDescription
-p, --port <PORT>8545RPC port

Example

nexus dev node --port 8545

Output

→ Starting local node on port 8545...
For production use, run the full node binary instead of the dev node.

Template Examples

Basic Template

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 handle() {
        // Handle function logic
        ret::u32(0)
    }
}

Ownable Template

use nexus_sdk::{
    solidity::*,
    contract_api::ez::ret,
    require,
};

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);
        ret::u32(1)
    }
}

nexus_fn! {
    fn set_owner(new_owner: Address) {
        let caller = Blockchain::msg.sender();
        let current_owner = OWNER.get(&b"val".as_slice());
        require!(caller == current_owner, "Only owner");
        
        OWNER.set(&b"val".as_slice(), new_owner);
        ret::u32(1)
    }
}

nexus_fn! {
    fn get_owner() {
        let owner = OWNER.get(&b"val".as_slice());
        ret::bytes(&owner.0)
    }
}

NEP-20 Template

use nexus_sdk::{
    solidity::{*, SafeMath},
    contract_api::ez::ret,
    require,
};
use nexus_sdk::solidity::uint256 as U256;

static BALANCES: Mapping<Address, U256> = Mapping::new(b"bal");
static ALLOWANCES: DoubleMapping<Address, Address, U256> = DoubleMapping::new(b"allow");
static TOTAL_SUPPLY: Mapping<&[u8], U256> = Mapping::new(b"supply");
static NAME: Mapping<&[u8], &str> = Mapping::new(b"name");
static SYMBOL: Mapping<&[u8], &str> = Mapping::new(b"symbol");
static DECIMALS: Mapping<&[u8], u8> = Mapping::new(b"decimals");

nexus_fn! {
    fn init(name: &str, symbol: &str, decimals: u8, initial_supply: U256) {
        let sender = Blockchain::msg.sender();
        NAME.set(&b"val".as_slice(), name);
        SYMBOL.set(&b"val".as_slice(), symbol);
        DECIMALS.set(&b"val".as_slice(), decimals);
        TOTAL_SUPPLY.set(&b"val".as_slice(), initial_supply);
        BALANCES.set(&sender, initial_supply);
        
        emit("Transfer", &[]);
        ret::u32(1)
    }
}

nexus_fn! {
    fn transfer(to: Address, amount: U256) {
        let _guard = ReentrancyGuard::new();
        let sender = Blockchain::msg.sender();
        
        let sender_bal = BALANCES.get(&sender);
        require!(sender_bal >= amount, "Insufficient balance");
        
        BALANCES.set(&sender, sender_bal.sub(amount));
        let to_bal = BALANCES.get(&to);
        BALANCES.set(&to, to_bal.add(amount));
        
        emit("Transfer", &[]);
        ret::u32(1)
    }
}

nexus_fn! {
    fn balanceOf(addr: Address) {
        let bal = BALANCES.get(&addr);
        let mut out = [0u8; 32];
        bal.to_little_endian(&mut out);
        ret::u256(&out)
    }
}

Development Workflow

# 1. Scaffold a new project
nexus dev scaffold my_token --template nep20

# 2. Edit the contract
cd my_token
# ... edit src/lib.rs ...

# 3. Compile
cargo build --target wasm32-unknown-unknown --release

# 4. Validate
nexus dev validate ./target/wasm32-unknown-unknown/release/my_token.wasm

# 5. Deploy
nexus contract deploy \
  --wasm ./target/wasm32-unknown-unknown/release/my_token.wasm \
  --name my_token \
  --from my-wallet