Skip to content

Instantly share code, notes, and snippets.

@anhdiepmmk
Last active November 20, 2021 12:49
Show Gist options
  • Save anhdiepmmk/3c97be260b03ab72f7d21afc69e60b50 to your computer and use it in GitHub Desktop.
Save anhdiepmmk/3c97be260b03ab72f7d21afc69e60b50 to your computer and use it in GitHub Desktop.
const {
Client,
TokenCreateTransaction,
PrivateKey,
TokenType,
TokenSupplyType,
TokenMintTransaction,
TokenNftInfoQuery,
NftId,
} = require("@hashgraph/sdk");
const accountId = ".....";
const privateKey =
"....";
const client = Client.forTestnet();
client.setOperator(accountId, privateKey);
async function main() {
const bomThoiToken = await new TokenCreateTransaction()
.setTokenName("Bom Thoi")
.setTokenSymbol("BT")
.setDecimals(0)
.setInitialSupply(0)
.setSupplyKey(PrivateKey.fromString(privateKey))
.setTokenType(TokenType.NonFungibleUnique)
.setSupplyType(TokenSupplyType.Finite)
.setMaxSupply(10)
.setTreasuryAccountId(accountId)
.execute(client);
const tokenReceipt = await bomThoiToken.getReceipt(client);
const tokenId = tokenReceipt.tokenId;
console.log("The new token ID is: " + tokenId);
// Minting
const token_1 = await new TokenMintTransaction()
.setTokenId(tokenId)
.setMetadata([Buffer.from("Some metaData")])
.execute(client);
const receipt = await token_1.getReceipt(client);
const nft_serial = receipt.serials[0].toNumber();
console.log("NTF serial is: ", nft_serial);
const nft_info = await new TokenNftInfoQuery()
.setNftId(new NftId(tokenId, nft_serial))
.execute(client);
const metadata = nft_info[0].metadata.toString();
console.log("Token Metadata is: ", metadata);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment