Search code examples
solanasolana-web3jssolana-program-library

Can I do solana spl-token authorize mint --disable but from javascript?


I am trying create an NFT mint, I know how to do it from CLI, but I need to do it from JS, I am looking at the code of @solana/spl-token package, but cannot find API analogous to

spl-token authorize <TOKEN_ID> mint --disable

Does anyone know how to do it?


Solution

  • You certainly can! Here's some code that doesn't compile to get you started:

    import { Connection, PublicKey, Keypair } from '@solana/web3.js';
    import { AuthorityType, setAuthority } from '@solana/spl-token';
    
    const mint = new PublicKey("mint in base 58");
    const payer = new Keypair(...);
    const mintAuthority = new Keypair(...);
    const connection = new Connection
    await setAuthority(
        connection,
        payer,
        mint,
        mintAuthority,
        AuthorityType.MintTokens,
        null, // this sets the mint authority to null
    );
    

    Adapted from https://github.com/solana-labs/solana-program-library/blob/7c7507f4ec1f320bbc33af459d4d8b5573a6a906/token/js/test/e2e/setAuthority.test.ts#L88