In this topic you will know how to create new Jetton and mint it using TonSDK.Net
Preparing Metadata
You can create Jettons with OffChain or OnChain metadata using structs in TonSdk.Contracts.Jetton:
// offchain metadata JettonMinterOptions options =newJettonMinterOptions(){ AdminAddress =newAddress(/* admin address */), JettonContent =newJettonOffChainContent() { ContentUri ="https://example.com/metadata.json"// your metadata link }};
// onchain metadata JettonMinterOptions options =newJettonMinterOptions(){ AdminAddress =newAddress(/* admin address */), JettonContent =newJettonOnChainContent() { Name ="My Best Token", Symbol ="MBT", Description ="This is the best description." Decimals =9,// optional Image ="https://example.com/image.png"// optional }};
Creating new Jetton Minter
To create new jetton, you can use JettonMinter class to create it with JettonMinterOptions presented above.
For example, we will use WalletV4. You can find more examples for different contracts here.
// create http parameters for ton client HttpParameters tonClientParams =newHttpParameters{ Endpoint ="https://toncenter.com/api/v2/jsonRPC", ApiKey ="xxx"};// create ton client to fetch data and send bocTonClient tonClient =newTonClient(TonClientType.HTTP_TONCENTERAPIV2, tonClientParams);// create new mnemonic or use existingMnemonic mnemonic =newMnemonic();// create wallet optionsWalletV4Options options =newWalletV4Options(){ PublicKey =mnemonic.Keys.PublicKey,};// create wallet instanceWalletV4 wallet =newWalletV4(optionsV4,2); // creating options with onchain metadata JettonMinterOptions opts =newJettonMinterOptions(){ AdminAddress =wallet.Address, JettonContent =newJettonOnChainContent() { Name ="My Best Token", Symbol ="MBT", Description ="This is the best description." Decimals =9,// optional Image ="https://example.com/image.png"// optional }};// creating jetton minter with optionsJettonMinter minter =newJettonMinter(opts);// getting seqno using tonClientuint? seqno =awaittonClient.Wallet.GetSeqno(wallet.Address);// creating jetton minter deploy messagevar msg =wallet.CreateTransferMessage(new[]{newWalletTransfer { Message =newInternalMessage(newInternalMessageOptions { Info =newIntMsgInfo(newIntMsgInfoOptions { Dest =minter.Address, Value =newCoins(0.05) }), Body =null, StateInit =minter.StateInit }), Mode =3// message mode }}, seqno ??0).Sign(m.Keys.PrivateKey);// send this message via TonClientawaitclient.SendBoc(msg.Cell);// print jetton master contractConsole.WriteLine(minter.Address);
Minting Jettons
After that we created our Jetton Minter and deployed it, we can mint more jettons using CreateMintRequest method:
// we will use same wallet and minter like in prev code block// create jetton mint optionsJettonMintOptions mintOptions =newJettonMintOptions(){ JettonAmount =newCoins(10000000),// jetton amount to mint Amount =newCoins(0.05),// amount send to jetton wallet Destination =wallet.Address// address which will get jettons};// create jetton mint request bodyCell jettonMintBody =JettonMinter.CreateMintRequest(mintOptions);// getting seqno using tonClientuint? seqno =awaittonClient.Wallet.GetSeqno(wallet.Address);// creating mint messagevar msg =wallet.CreateTransferMessage(new[]{newWalletTransfer { Message =newInternalMessage(newInternalMessageOptions { Info =newIntMsgInfo(newIntMsgInfoOptions { Dest =minter.Address, Value =newCoins(0.05) }), Body = jettonMintBody }), Mode =3// message mode }}, seqno ??0).Sign(m.Keys.PrivateKey);// send this message via TonClientawaitclient.SendBoc(msg.Cell);