Skip to content

DRC721 reference implementation for Dusk: contract, data-driver, and minimal web management UI.

License

Notifications You must be signed in to change notification settings

Dusk-Forge/drc721-reference

Repository files navigation

DRC721 - Public NFT Standard for DuskDS

Status: Reference implementation / draft: the standard and interface are still open for feedback. Please open an issue (or PR) with suggestions, edge-cases, or compatibility concerns.

A minimal ERC721-like non-fungible token reference implementation for the DuskDS network.

Repo layout

  • contract/ — the on-chain DRC721 contract (WASM)
  • types/ — shared types (accounts, call args, events, error strings)
  • tools/ — helper CLI tooling (constructor args)
  • tests/ — spec tests + VM harness
  • web/ — minimal admin/management UI (connect + read + send tx)

Interface

Views

  • name() -> String
  • symbol() -> String
  • base_uri() -> String
  • token_uri(TokenUri) -> String
  • total_supply() -> u64
  • balance_of(BalanceOf) -> u64
  • owner_of(OwnerOf) -> Account
  • get_approved(GetApproved) -> Account
  • is_approved_for_all(IsApprovedForAll) -> bool

State-changing

  • approve(ApproveCall)
  • set_approval_for_all(SetApprovalForAllCall)
  • transfer_from(TransferFromCall)

Events

  • transfer (events::Transfer)
  • approval (events::Approval)
  • approval_for_all (events::ApprovalForAll)

Build

Prereqs

  • Rust toolchain pinned in rust-toolchain.toml
  • wasm target:
    rustup target add wasm32-unknown-unknown
  • jq is used by Makefiles (cargo metadata parsing).
  • Optional: wasm-opt (from Binaryen) for optimized outputs.

1) Build the contract WASM

make wasm-opt
# output: target/wasm32-unknown-unknown/release/drc721_opt.wasm

2) Build the data-driver WASM (off-chain)

The data-driver is auto-generated from the contract via Dusk Forge (no separate data-driver/ crate) and can be used by any runtime that supports WASM.

make data-driver
# output: target/data-driver/wasm32-unknown-unknown/release/drc721_opt.wasm

This command also copies the WASM into web/public/data_driver.wasm.

3) Run the web management UI

cd web
npm i
npm run dev

Open:

http://localhost:5173/?network=testnet&contractId=0xYOUR_32B_CONTRACT_ID

Optional overrides:

  • &nodeUrl=https://testnet.nodes.dusk.network
  • &driverUrl=/data_driver.wasm

Deploy

1) Prepare constructor args (Init)

This repo expects an init.json in the repo root describing the initial distribution.

  • init.json is git-ignored (so you can safely keep local addresses / configs out of version control).
  • example.init.json is committed as a starting point.

Create your local init.json:

cp example.init.json init.json
# edit init.json

Example format:

{
  "base_uri": "ipfs://example-collection/",
  "initial_tokens": [
    { "account": { "External": "26brdzqNXEG1jTzCubJAPhks18bSSDY4n21ZW6VLYkCv6bBUdBAZZAbn1Coz1LPBYc4uEekBbzFnZvhL9untGCqRamhZS2cBV51fdZog3qkP3NbMEaqgNMcKEahAFV8t2Cke" }, "token_id": "1" }
  ]
}

Notes:

  • External is a public account (base58).
  • Token IDs are u64 and accepted as JSON strings (to avoid JS precision issues).
  • base_uri is optional; leave it empty or omit it to disable token_uri.
  • token_uri is computed as base_uri + token_id, so include a trailing / if you want .../1.

Generate the rkyv-encoded hex string expected by most deploy tooling:

make init-args FILE=./init.json
# prints: <hex>

Note: make init-args defaults to ./init.json if you don't pass FILE=....

2) Deploy the WASM

Deploy using your preferred tooling (e.g. rusk-wallet contract-deploy).

Deploy tooling must pass constructor args. To deploy with zero supply, use an empty initial_tokens list in Init.

Tests

The repo includes a small spec test-suite that runs the contract in dusk-vm and asserts the classic ERC721 behaviors (ownership, approvals, events, failure cases).

It also deploys a tiny helper contract to prove the "contract caller" path works (i.e. sender_account() resolves to Account::Contract(...) for ICC calls).

Run the tests:

make test

This will:

  1. Build contract/ to target/wasm32-unknown-unknown/release/drc721.wasm
  2. Build the helper contract to target/wasm32-unknown-unknown/release/drc721_test_caller.wasm
  3. Run cargo test -p drc721-tests

Notes

  • init(Init) is intended to be called at deployment with an initial distribution.
  • The contract is transparent only (requires a public sender, shielded tx not supported).
  • ZERO_ADDRESS is reserved for mint events (from = ZERO_ADDRESS).

License

MIT © Dusk Forge.

About

DRC721 reference implementation for Dusk: contract, data-driver, and minimal web management UI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published