Update NFT Schema

Add New Action

create file add_action.ts

vim add_action.ts
add_action.ts
import { SixDataChainConnector, BASE64 } from "@sixnetwork/six-data-chain-sdk";
import exampleNewAction from "./resource/new-action.json";
const main = async () => {
  const sixConnector = new SixDataChainConnector();
  // specify the RPC URL of the chain
  sixConnector.rpcUrl = "https://rpc1.fivenet.sixprotocol.net:443";

  // Retrieve acctount signer from private key or mnemonic
  const accountSigner = await sixConnector.accounts.privateKeyToAccount(<string_private_key_or_mnemonic_seed>)
  // Get index of account
  const address = (await accountSigner.getAccounts())[0].address;
  const rpcClient = await sixConnector.connectRPCClient(accountSigner);
  // Encode NFT data to base64
  const encodeBase64NewAction = BASE64.encode(JSON.stringify(exampleNewAction));
  const msg = await rpcClient.nftmngrModule.msgAddAction({
    creator: address,
    code: "six.rocket_ticket",
    base64NewAction: encodeBase64NewAction,
  });
  const txResponse = await rpcClient.nftmngrModule.signAndBroadcast([msg], {
    fee: { amount: [{ denom: "usix", amount: "10000000" }], gas: "1500000" },
    memo: "Add New Action To rocket_ticket",
  });

  console.log(txResponse);
};
main();

Execute add_action.ts

npx ts-node ./add_action.ts

When it is successful it will response similar to:

{
  code: 0,
  height: 1346,
  rawLog: '[{"events":[{"type":"add_action","attributes":[{"key":"nft_schema_code","value":"six.rocket_ticket"},{"key":"add_action_name","value":"new_action"},{"key":"add_action_result","value":"success"}]},{"type":"message","attributes":[{"key":"action","value":"add_action"}]}]}]',
  transactionHash: '71B92F3DFB5C6A3A0A7FE14DDB856DC3F2EB7B956DB9338CAE962C3D9FF95672',
  gasUsed: 300626,
  gasWanted: 1500000
}

Add New Attribute

create file add_attribute.ts

add_attribute.ts
import { SixDataChainConnector, BASE64 } from "@sixnetwork/six-data-chain-sdk";
import exampleNewAttribute from "./resource/new-attribute.json";
const main = async () => {
  const sixConnector = new SixDataChainConnector();
  // specify the RPC URL of the chain
  sixConnector.rpcUrl = "https://rpc1.fivenet.sixprotocol.net:443";

  // Retrieve acctount signer from private key or mnemonic
  const accountSigner = await sixConnector.accounts.privateKeyToAccount(<string_private_key_or_mnemonic_seed>)
  // Get index of account
  const address = (await accountSigner.getAccounts())[0].address;
  const rpcClient = await sixConnector.connectRPCClient(accountSigner);
  // Encode NFT data to base64
  const encodeBase64NewAttribute = BASE64.encode(JSON.stringify(exampleNewAttribute));
  const msg = await rpcClient.nftmngrModule.msgAddAttribute({
    creator: address,
    code: "six.rocket_ticket",
    location:1, // 0: NFT Attribute(non-Dynamic Attribute), 1: Token Attribute (Dynamic Attribute)
    base64NewAttriuteDefenition: encodeBase64NewAttribute,
  });
  const txResponse = await rpcClient.nftmngrModule.signAndBroadcast([msg], {
    fee: { amount: [{ denom: "usix", amount: "10000000" }], gas: "1500000" },
    memo: "Add New Attribute to NFT Schema",
  });

  console.log(txResponse);
};
main();

Execute add_attribute.ts

npx ts-node ./add_attribute.ts

When it is successful it will response similar to:

{
  code: 0,
  height: 1762,
  rawLog: '[{"events":[{"type":"add_attribute","attributes":[{"key":"nft_schema_code","value":"six.rocket_ticket"},{"key":"add_attribute_name","value":"new_attribute"},{"key":"add_attribute_location","value":"TOKEN_ATTRIBUTE"},{"key":"add_attribute_result","value":"success"}]},{"type":"message","attributes":[{"key":"action","value":"add_attribute"}]}]}]',
  transactionHash: '1C15FF421FB33696C7773861B8B215E72203346FAC81F8FE467F503050F589DD',
  gasUsed: 303360,
  gasWanted: 1500000
}

Last updated