Secret Contract Development Toolkit - SNIP-721 Interface

⚠️ This package is a sub-package of the secret-toolkit package. Please see its crate page for more context.

These functions are meant to help you easily interact with SNIP-721 compliant NFT contracts.

Handle Messages

You can create a HandleMsg variant and call the to_cosmos_msg function to generate the CosmosMsg that should be pushed onto the InitResponse or HandleResponse messages Vec.

Or you can call the individual function for each Handle message to generate the appropriate callback CosmosMsg.

Example: ```rust let recipient = HumanAddr("ADDRESSTOTRANSFERTO".tostring()); let tokenid = "TOKENID".tostring(); let memo = Some("TRANSFERMEMO".tostring()); let padding = None; let blocksize = 256; let callbackcodehash = "TOKENCONTRACTCODEHASH".tostring(); let contractaddr = HumanAddr("TOKENCONTRACTADDRESS".tostring());

let cosmos_msg = transfer_nft_msg(
    recipient,
    token_id,
    memo,
    padding,
    block_size,
    callback_code_hash,
    contract_addr,
)?;

Ok(HandleResponse {
    messages: vec![cosmos_msg],
    log: vec![],
    data: None,
})

`` All you have to do to call a SNIP-721 Handle function is call the appropriate toolkit function, and place the resultingCosmosMsgin themessagesVec of the InitResponse or HandleResponse. In this example, we are transferring an NFT named "TOKEN_ID" to the recipient address. We are not using thepadding` field of the Transfer message, but instead, we are padding the entire message to blocks of 256 bytes.

You probably have also noticed that CreateViewingKey is not supported. This is because a contract can not see the viewing key that is returned because it has already finished executing by the time CreateViewingKey would be called. If a contract needs to have a viewing key, it must create its own sufficiently complex viewing key, and pass it as a parameter to SetViewingKey. You can see an example of creating a complex viewing key in the Snip20 Reference Implementation. It is also highly recommended that you use the block_size padding option to mask the length of the viewing key your contract has generated.

Queries

These are the types that the SNIP-721 toolkit queries can return ```rust pub struct ContractInfo { pub name: String, pub symbol: String, }

pub struct NumTokens { pub count: u32, }

pub struct TokenList { pub tokens: Vec, }

pub struct Cw721Approval { pub spender: HumanAddr, pub expires: Expiration, }

pub struct OwnerOf { pub owner: Option, pub approvals: Vec, }

pub struct Metadata { pub name: Option, pub description: Option, pub image: Option, }

pub struct AllNftInfo { pub access: OwnerOf, pub info: Option, }

pub struct Snip721Approval { pub address: HumanAddr, pub viewownerexpiration: Option, pub viewprivatemetadataexpiration: Option, pub transferexpiration: Option, }

pub struct NftDossier { pub owner: Option, pub publicmetadata: Option, pub privatemetadata: Option, pub displayprivatemetadataerror: Option, pub ownerispublic: bool, pub publicownershipexpiration: Option, pub privatemetadataispublic: bool, pub privatemetadataispublicexpiration: Option, pub tokenapprovals: Option>, pub inventoryapprovals: Option>, }

pub struct TokenApprovals { pub ownerispublic: bool, pub publicownershipexpiration: Option, pub privatemetadataispublic: bool, pub privatemetadataispublicexpiration: Option, pub tokenapprovals: Vec, }

pub struct ApprovedForAll { pub operators: Vec, }

pub struct InventoryApprovals { pub ownerispublic: bool, pub publicownershipexpiration: Option, pub privatemetadataispublic: bool, pub privatemetadataispublicexpiration: Option, pub inventoryapprovals: Vec, }

pub enum TxAction { Transfer { from: HumanAddr, sender: Option, recipient: HumanAddr, }, Mint { minter: HumanAddr, recipient: HumanAddr, }, Burn { owner: HumanAddr, burner: Option, }, }

pub struct Tx { pub txid: u64, pub blockheight: u64, pub blocktime: u64, pub tokenid: String, pub action: TxAction, pub memo: Option, }

pub struct TransactionHistory { pub total: u64, pub txs: Vec, }

pub struct Minters { pub minters: Vec, }

pub struct IsUnwrapped { pub tokenisunwrapped: bool, }

pub struct VerifyTransferApproval { pub approvedforall: bool, pub firstunapprovedtoken: Option, } `` You can create a QueryMsg variant and call thequery` function to query a SNIP-721 token contract.

Or you can call the individual function for each query.

Example: ```rust let tokenid = "TOKENID".tostring(); let viewer = Some(ViewerInfo { address: HumanAddr("VIEWER'SADDRESS".tostring()), viewingkey: "VIEWER'SKEY".tostring(), }); let includeexpired = None; let blocksize = 256; let callbackcodehash = "TOKENCONTRACTCODEHASH".tostring(); let contractaddr = HumanAddr("TOKENCONTRACTADDRESS".tostring());

let nft_dossier =
    nft_dossier_query(&deps.querier, token_id, viewer, include_expired, block_size, callback_code_hash, contract_addr)?;

`` In this example, we are doing an NftDossier query on the token named "TOKEN_ID", supplying the address and viewing key of the querier, and storing the response in the nft_dossier variable, which is of the NftDossier type defined above. Because noinclude_expired` was specified, the response defaults to only displaying approvals that have not expired, but approvals will only be displayed if the viewer is the owner of the token. The query message is padded to blocks of 256 bytes.