Skip to main content

SAVITRI-721: NFT Standard

SAVITRI-721 (SNT1 -- Savitri Non-Fungible Token) is the NFT standard for the Savitri Network, equivalent to Ethereum's ERC-721. Each token has a unique ID and a single owner.

Interface

FunctionParamsReturnsDescription
balance_ofowneru64Number of NFTs owned by address
owner_oftoken_idaddressOwner of a specific token
transfer_fromfrom, to, token_idResultTransfer an NFT
approveto, token_idResultApprove address to transfer token
safe_transfer_fromfrom, to, token_idResultTransfer with safety checks
token_uritoken_idStringGet token metadata URI
mintto, token_id, uriResultMint a new NFT

Storage Layout

Slot RangePurposeDerivation
0-99BaseContract (reserved)Direct
100+Token ownerskeccak256(100 || token_id)
200+Token balanceskeccak256(200 || address)
300+Token approvalskeccak256(300 || token_id)
400+Token URIskeccak256(400 || token_id)

Keccak256 hashing prevents slot collisions between categories (e.g., token_id 100 won't collide with the balances base slot).

Minting an NFT

use savitri_contracts::contracts::standards::savitri721::SAVITRI721;

SAVITRI721::mint(
&mut contract_storage,
&storage,
&recipient, // [u8; 32]
42, // token_id: u64
"ipfs://Qm.../meta", // token URI
&mut event_system,
Some(&mut gas_meter),
)?;

Transferring

// Direct transfer
SAVITRI721::transfer_from(
&mut contract_storage,
&storage,
&from, // current owner
&to, // new owner
42, // token_id
&mut event_system,
Some(&mut gas_meter),
)?;

Querying

// Who owns token #42?
let owner = SAVITRI721::owner_of(&contract_storage, &storage, 42)?;

// How many NFTs does this address own?
let count = SAVITRI721::balance_of(&contract_storage, &storage, &address)?;

// Get metadata URI
let uri = SAVITRI721::token_uri(&contract_storage, &storage, 42)?;

Events

EventFieldsDescription
Transferfrom, to, token_idNFT transferred
Approvalowner, approved, token_idApproval granted
Mintto, token_idNew NFT minted

Via SDK

use savitri_sdk::{ContractClient, Wallet};

let contract = ContractClient::from_url_and_wallet("http://localhost:8545", wallet)?;

// Mint NFT via contract call
let tx = contract.call_contract(
&nft_contract_address,
b"mint",
&encode_mint_args(recipient, token_id, uri),
Some(0),
).await?;