【问题标题】:How do I remove the minting authority from my custom token in Solana using @solana/web3.js?如何使用 @solana/web3.js 从 Solana 中的自定义令牌中删除铸币权限?
【发布时间】:2021-11-02 03:16:28
【问题描述】:

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

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: javascript blockchain web3js solana


【解决方案1】:

为防止再铸币,您需要将铸币权限设置为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

【讨论】:

    【解决方案2】:

    扩展 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])
    
    })()
    

    【讨论】:

      猜你喜欢
      • 2021-09-15
      • 2021-12-05
      • 2021-12-10
      • 2021-12-20
      • 2021-09-13
      • 2022-01-19
      • 2021-09-27
      • 2021-12-22
      • 2022-11-27
      相关资源
      最近更新 更多