⚠️ 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.
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:
```ignore let recipient = "ADDRESSTOTRANSFERTO".tostring(); let tokenid = "TOKENID".tostring(); let memo = Some("TRANSFERMEMO".tostring()); let padding = None; let blocksize = 256; let callbackcodehash = "TOKENCONTRACTCODEHASH".tostring(); let contractaddr = "TOKENCONTRACTADDRESS".tostring();
let cosmos_msg = transfer_nft_msg(
recipient,
token_id,
memo,
padding,
block_size,
callback_code_hash,
contract_addr,
)?;
Ok(Response::new().add_message(cosmos_msg))
```
All you have to do to call a SNIP-721 Handle function is call the appropriate toolkit function, and place the resulting CosmosMsg
in the messages
Vec of the InitResponse or HandleResponse. In this example, we are transferring an NFT named "TOKEN_ID" to the recipient address. We are not using the padding
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.
These are the types that the SNIP-721 toolkit queries can return
```ignore 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: String, pub expires: Expiration, }
pub struct OwnerOf {
pub owner: Option
pub struct Metadata {
pub name: Option
pub struct AllNftInfo {
pub access: OwnerOf,
pub info: Option
pub struct Snip721Approval {
pub address: String,
pub viewownerexpiration: Option
pub struct NftDossier {
pub owner: Option
pub struct TokenApprovals {
pub ownerispublic: bool,
pub publicownershipexpiration: Option
pub struct ApprovedForAll {
pub operators: Vec
pub struct InventoryApprovals {
pub ownerispublic: bool,
pub publicownershipexpiration: Option
pub enum TxAction {
Transfer {
from: String,
sender: 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 the query
function to query a SNIP-721 token contract.
Or you can call the individual function for each query.
Example:
```ignore let tokenid = "TOKENID".tostring(); let viewer = Some(ViewerInfo { address: "VIEWER'SADDRESS".tostring(), viewingkey: "VIEWER'SKEY".tostring(), }); let includeexpired = None; let blocksize = 256; let callbackcodehash = "TOKENCONTRACTCODEHASH".tostring(); let contractaddr = "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 "TOKENID", supplying the address and viewing key of the querier, and storing the response in the nftdossier variable, which is of the NftDossier type defined above. Because no include_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.