1

Hi I have a base58 string for an SPL token address (called a mint in the Solana docs); This is how I generated this string:

    const mint = await createMint(
        connection,
        payer,
        payer.publicKey,
        payer.publicKey,
        9 // We are using 9 to match the CLI decimal default exactly
      );

      //PublicKey {
      // _bn: <BN: f18d4c56c6c9998782580321e8464aea9ffd4452879d5575aa62b856e837c871>>
      //}


      var  mint58 =  mint.toBase58();
      //HFvDm6RsgU6Hxscw2YHhPMmjRVzTEigW1ma61kB9M79i

How to go the other way around, i.e. get from the mint58 to the public key in the correct data structure?

Thanks

1 Answer 1

4

You can get the correct key by calling new PublicKey(string).

The constructor for PublicKey takes a number of different types: number | string | Buffer | Uint8Array | number[]

https://solana-labs.github.io/solana-web3.js/modules.html#PublicKeyInitData

import * as web3 from '@solana/web3.js'

const mint58 = "HFvDm6RsgU6Hxscw2YHhPMmjRVzTEigW1ma61kB9M79i"
const pubkey = new web3.PublicKey(mint58);

console.log(pubkey);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.