Learn how to send SNIP721s with SecretJS.
import { SecretNetworkClient, Wallet } from "secretjs";
const wallet = new Wallet("Your mnemonic words go here");
const secretjs = new SecretNetworkClient({
chainId: "pulsar-3",
url: "https://api.pulsar3.scrttestnet.com",
wallet: wallet,
walletAddress: wallet.address,
});
const addMinterMsg = await secretjs.tx.snip721.addMinter(
{
contract_address: contractAddress,
msg: { add_minters: { minters: [accounts[0].address] } },
sender: accounts[0].address,
},
{
gasLimit: 100_000,
},
);
const mintMsg = await secretjs.tx.snip721.mint(
{
contract_address :contractAddress,
sender: accounts[0].address,
msg: {
mint_nft: {
token_id: "1",
},
},
},
{
gasLimit: 200_000,
},
);
const txExec = await secretjs.tx.snip721.send(
{
sender: secretjs.address,
contract_address: contractAddress,
msg: {
send_nft: {
contract: accounts[1].address,
token_id: "1",
},
},
},
{
gasLimit: 50_000,
},
);
const addMinterMsg = new MsgExecuteContract({
sender: accounts[0].address,
contract_address: contractAddress,
// codeHash, // Test MsgExecuteContract without codeHash
msg: { add_minters: { minters: [accounts[0].address] } },
sentFunds: [],
});
const mintMsg = new MsgExecuteContract({
sender: accounts[0].address,
contract_address: contractAddress,
code_hash: codeHash,
msg: {
mint_nft: {
token_id: "1",
owner: accounts[0].address,
public_metadata: {
extension: {
image:
"https://scrt.network/secretnetwork-logo-secondary-black.png",
name: "secretnetwork-logo-secondary-black",
},
},
private_metadata: {
extension: {
image:
"https://scrt.network/secretnetwork-logo-primary-white.png",
name: "secretnetwork-logo-primary-white",
},
},
},
},
sentFunds: [],
});
const tx = await secretjs.tx.broadcast([addMinterMsg, mintMsg], {
gasLimit: 5_000_000,
});
let permit = await secretjs.utils.accessControl.permit.sign(accounts[0].address, "secretdev-1", "Test", [contractAddress], ["owner"], false)
let tokens2 = await secretjs.query.snip721.GetOwnedTokens({
contract: { address: contractAddress, codeHash },
owner: accounts[0].address,
auth: { permit: permit },
});
await secretjs.tx.snip721.setViewingKey(
{
contract_address: contractAddress,
sender: accounts[0].address,
msg: {
set_viewing_key: {
key: "hello",
},
},
},
{
gasLimit: 100_000,
},
);
let tokens = await secretjs.query.snip721.GetOwnedTokens({
contract: { address: contractAddress, codeHash },
owner: accounts[0].address,
auth: { viewer: { viewing_key: "hello", address: accounts[0].address } },
});