Deploy NFT Gen2

Deploy NFT Schema

Initial Project

npm init -y

install typescript

npm install --save-dev typescript
npm install --save ts-node

create and modify tsconfig.json

vim tsconfig.json
tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2022",
    "sourceMap": true,
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": false,
    "resolveJsonModule": true,          
    "esModuleInterop": true,            
  }
}

Create resource directory

mkdir resource

Download or Save all resource from Example Resources Page to this directory

Install DataChainSdk package

npm i @sixnetwork/six-data-chain-sdk

create file deploy.ts

vim deploy.ts
import { SixDataChainConnector, BASE64 } from "@sixnetwork/six-data-chain-sdk";
import nft_schema from "./resource/nft-schema-example.json";
const main = async () => {
  const sixConnector = new SixDataChainConnector();
  sixConnector.rpcUrl = "https://rpc1.fivenet.sixprotocol.net:443";
  const accountSigner = await sixConnector.accounts.privateKeyToAccount(<string_private_key_or_mnemonic_seed>)
  const address = (await accountSigner.getAccounts())[0].address;
  const rpcClient = await sixConnector.connectRPCClient(accountSigner);

  const encodeBase64Schema = BASE64.encode(JSON.stringify(nft_schema));
  const msg = await rpcClient.nftmngrModule.msgCreateNFTSchema({
    creator: address,
    nftSchemaBase64: encodeBase64Schema,
  });

  const txResponse = await rpcClient.nftmngrModule.signAndBroadcast([msg], {
    fee: { amount: [{ denom: "usix", amount: "10000000" }], gas: "1500000" },
    memo: "create nft schema",
  });
  console.log(txResponse);
};
main();

To obtain mnemonic seed or private key, please read at Create Account Page

Execute deploy.ts

npx ts-node ./deploy.ts

When it is successful it will response similar to:

If return code != 0 then execution is failed.

{
  code: 0,
  height: 718,
  rawLog: '[{"events":[{"type":"coin_received","attributes":[{"key":"receiver","value":"6x1sj4ecdg85wcxjm5vzrvedrfew0hlx6j6xsjsnr"},{"key":"amount","value":"200000000usix"}]},{"type":"coin_spent","attributes":[{"key":"spender","value":"6x1myrlxmmasv6yq4axrxmdswj9kv5gc0ppx95rmq"},{"key":"amount","value":"200000000usix"}]},{"type":"craete_schema","attributes":[{"key":"create_schema_code","value":"six.rocket_ticket"},{"key":"create_schema_result","value":"success"}]},{"type":"message","attributes":[{"key":"action","value":"create_nft_schema"},{"key":"sender","value":"6x1myrlxmmasv6yq4axrxmdswj9kv5gc0ppx95rmq"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"6x1sj4ecdg85wcxjm5vzrvedrfew0hlx6j6xsjsnr"},{"key":"sender","value":"6x1myrlxmmasv6yq4axrxmdswj9kv5gc0ppx95rmq"},{"key":"amount","value":"200000000usix"}]}]}]',
  transactionHash: 'C214C4D36AE54944D798062EF97D46FA7532701CB401692E5276D88FB24E9DE7',
  gasUsed: 470314,
  gasWanted: 1500000
}

Create NFT Metadata (mint)

create file mint.ts

vim mint.ts
import { SixDataChainConnector, BASE64 } from "@sixnetwork/six-data-chain-sdk";
import exampleNFTData from "./resource/nft-metadata-example.json";
const main = async () => {
  const sixConnector = new SixDataChainConnector();
  // specify the RPC URL of the chain
  sixConnector.rpcUrl = "http://localhost:26657";

  // 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 encodeBase64Metadata = BASE64.encode(JSON.stringify(exampleNFTData));
  const msg = await rpcClient.nftmngrModule.msgCreateMetadata({
    creator: address,
    nftSchemaCode: "six.rocket_ticket",
    tokenId: "1",
    base64NFTData: encodeBase64Metadata,
  });
  const txResponse = await rpcClient.nftmngrModule.signAndBroadcast([msg], {
    fee: { amount: [{ denom: "usix", amount: "10000000" }], gas: "1500000" },
    memo: "Mint NFT Metadata Token 1",
  });
  console.log(txResponse);
};
main();

Execute mint.ts

npx ts-node ./deploy.ts

When it is successful it will response similar to:

{
  code: 0,
  height: 224,
  rawLog: '[{"events":[{"type":"create_metadata","attributes":[{"key":"nft_schema_code","value":"six.rocket_ticket"},{"key":"token_id","value":"1"},{"key":"create_metadata_result","value":"success"}]},{"type":"message","attributes":[{"key":"action","value":"create_metadata"}]}]}]',
  transactionHash: '16534DF0F2BC3E39D4C6971742B114B279B250C8B7D0C9408BDFF340B1E2E3AB',
  gasUsed: 362193,
  gasWanted: 1500000
}

Last updated