# Deploy NFT Gen2

## Deploy NFT Schema

#### Initial Project

```bash
npm init -y
```

install typescript

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

create and modify tsconfig.json

```bash
vim tsconfig.json
```

{% code title="tsconfig.json" %}

```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,            
  }
}
```

{% endcode %}

Create resource directory

```bash
mkdir resource
```

Download or Save all resource from [Example Resources Page](/nft-gen-2-tech-doc/getting-started/sdk-package-for-nodejs/example-resources.md) to this directory

Install DataChainSdk package

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

create file deploy.ts

```bash
vim deploy.ts
```

```typescript
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();
```

{% hint style="info" %}
To obtain mnemonic seed or private key, please read at [Create Account Page](/nft-gen-2-tech-doc/getting-started/getting-started/create-account.md)
{% endhint %}

Execute deploy.ts

```bash
npx ts-node ./deploy.ts
```

When it is successful it will response similar to:

{% hint style="info" %}
If return code != 0 then execution is failed.
{% endhint %}

```
{
  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

```bash
vim mint.ts
```

```typescript
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

```bash
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
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sixnetwork.gitbook.io/nft-gen-2-tech-doc/getting-started/sdk-package-for-nodejs/deploy-nft-gen2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
