繁体   English   中英

如何使用 @solana/web3.js 从 Solana 中的自定义令牌中删除铸币权限?

[英]How do I remove the minting authority from my custom token in Solana using @solana/web3.js?

我已经能够使用使用web3.Keypair.generate()生成的自定义钱包创建自定义令牌,但是我现在如何限制这些令牌的供应或删除这些 SPL 令牌的铸造权限?

为了防止更多的铸币,您需要将铸币权限设置为None 在 JS 中,您可以在使用 [1] 中的authorityType = MintTokens调用setAuthority期间简单地将newAuthority设置为null

[1] https://github.com/solana-labs/solana-program-library/blob/36e886392b8c6619b275f6681aed6d8aae6e70f9/token/js/client/token.js#L985

扩展 Jon Cinque 的答案

import { Connection, clusterApiUrl, Keypair, PublicKey } from '@solana/web3.js'
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'
import * as bs58 from 'bs58';

(async () => {
  const connection = new Connection(clusterApiUrl('mainnet-beta'))

  const bytes = bs58.decode(process.env.PRIVATE_KEY)
  const account = Keypair.fromSecretKey(bytes)

  const tokenMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v')
  const token = new Token(connection, tokenMint, TOKEN_PROGRAM_ID, account)

  await token.setAuthority(tokenMint, null, 'MintTokens', account.publicKey, [account])

})()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM