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:
let recipient = HumanAddr;
let token_id = "TOKEN_ID".to_string;
let memo = Some;
let padding = None;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string;
let contract_addr = HumanAddr;
let cosmos_msg = transfer_nft_msg?;
Ok
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.
Queries
These are the types that the SNIP-721 toolkit queries can return
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:
let token_id = "TOKEN_ID".to_string;
let viewer = Some;
let include_expired = None;
let block_size = 256;
let callback_code_hash = "TOKEN_CONTRACT_CODE_HASH".to_string;
let contract_addr = HumanAddr;
let nft_dossier =
nft_dossier_query?;
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 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.