我已经使用JavaScript SDK在HTS上创建了一个新令牌:
// Create an HTS Fungible Token
async function createFungibleToken(
client,
treasuryAccountId,
treasuryAccountPrivateKey,
) {
// Generate supply key
const supplyKeyForFT = PrivateKey.generateED25519();
// Confgiure the token
const createFTokenTxn = await new TokenCreateTransaction()
.setTokenName('PowerToken')
.setTokenSymbol('PT')
.setTokenType(TokenType.FungibleCommon)
.setDecimals(1)
.setInitialSupply(100)
.setTreasuryAccountId(treasuryAccountId)
.setSupplyKey(supplyKeyForFT)
.setMaxTransactionFee(new Hbar(30))
.freezeWith(client);
// Sign the transaction with the treasury account private key
const createFTokenTxnSigned = await
createFTokenTxn.sign(treasuryAccountPrivateKey);
const createFTokenTxnResponse = await
createFTokenTxnSigned.execute(client);
const createFtTokenTxnReceipt = await createFTokenTxnResponse.getReceipt(client);
const fungibleTokenId = createFtTokenTxnReceipt.tokenId;
console.log(`Fungible token ID: ${fungibleTokenId}`);
}
然后try 使用TransferTransaction()将其发送到帐户:
async function transferHtsToken(tokenId, senderAccountId, receiverAccoundId, myPrivateKey) {
const transferTransaction = new TransferTransaction()
.addTokenTransfer(tokenId, senderAccountId, -1)
.addTokenTransfer(tokenId, receiverAccoundId, 1)
.freezeWith(client);
const signTx = await transferTransaction.sign(myPrivateKey);
const txResponse = await signTx.execute(client);
const receipt = await txResponse.getReceipt(client);
const txStatus = receipt.status;
console.log(`Transaction status ${txStatus}`);
}
但是,我得到以下错误:
ReceiptStatusError: receipt for transaction 0.0.565763@1692941232.156398491 contained error status TOKEN_NOT_ASSOCIATED_TO_ACCOUNT
为什么有必要在Hedera上"关联"一个令牌?
我如何才能做到这一点?