SAVITRI-721: Estándar NFT
SAVITRI-721 (SNT1 -- Savitri Non-Fungible Token) es el estándar NFT para Savitri Network, equivalente al ERC-721 de Ethereum. Cada token tiene un ID único y un único propietario.
Interfaz
| Función | Parámetros | Retorna | Descripción |
|---|---|---|---|
balance_of | owner | u64 | Número de NFTs en propiedad de una dirección |
owner_of | token_id | address | Propietario de un token específico |
transfer_from | from, to, token_id | Result | Transferir un NFT |
approve | to, token_id | Result | Aprobar dirección para transferir token |
safe_transfer_from | from, to, token_id | Result | Transferir con verificaciones de seguridad |
token_uri | token_id | String | Obtener URI de metadatos del token |
mint | to, token_id, uri | Result | Acuñar un nuevo NFT |
Disposición del Almacenamiento
| Rango de Ranuras | Propósito | Derivación |
|---|---|---|
| 0-99 | BaseContract (reservado) | Directa |
| 100+ | Propietarios de tokens | keccak256(100 || token_id) |
| 200+ | Saldos de tokens | keccak256(200 || address) |
| 300+ | Aprobaciones de tokens | keccak256(300 || token_id) |
| 400+ | URIs de tokens | keccak256(400 || token_id) |
El hash Keccak256 previene colisiones de ranuras entre categorías (p. ej., el token_id 100 no colisionará con la ranura base de saldos).
Acuñación de un 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),
)?;
Transferencia
// 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),
)?;
Consultas
// 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)?;
Eventos
| Evento | Campos | Descripción |
|---|---|---|
Transfer | from, to, token_id | NFT transferido |
Approval | owner, approved, token_id | Aprobación otorgada |
Mint | to, token_id | Nuevo NFT acuñado |
Mediante el 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?;