Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8092

How to set updateAuthority for spl-token in time of mint with JavaScript?

$
0
0

Im using @solana/spl-token to mint a legacy token on Solana (not token2022).

The problem is that I cannot set any updateAuthority for it so I cannot set/update its metadata with Metaplex after minting.

Below is how I'm minting the token:

import { createMint, getOrCreateAssociatedTokenAccount, mintTo, setAuthority } from '@solana/spl-token';import { clusterApiUrl, Connection, Keypair, LAMPORTS_PER_SOL } from '@solana/web3.js';import { getKeypairFromFile } from "@solana-developers/helpers";const connection = new Connection(    clusterApiUrl('devnet'),'confirmed'  );export async function createAndMint( supply: number, decimals: number = 9) {const payer = await getKeypairFromFile("keypair.json");const mintAuthority = payer;const freezeAuthority = null;const mint = await createMint(  connection,  payer,  mintAuthority.publicKey,  freezeAuthority,  decimals  );console.log("Mint: ",mint.toBase58());const tokenAccount = await getOrCreateAssociatedTokenAccount(    connection,    payer,    mint,    payer.publicKey  )console.log("Token Account: ", tokenAccount.address.toBase58());await mintTo(    connection,    payer,    mint,    tokenAccount.address,    mintAuthority,    supply * (10 ** decimals),  ).then((tx) => {    console.log("Minted: ", supply, " tokens to ", tokenAccount.address.toBase58());    console.log("Signature: ", tx);  });  return mint;}

example of a minted token: https://solscan.io/token/F87BX1QSwXJsjFsUNMY8rConRa8eaAusFu2xmEKcQkzF?cluster=devnet

as you can see in the Authority section, there is no update Authority set for it (null).so I cannot set metadata with Metaplex for it.

But when I use spl-token CLI to create the token, updateAuthority is set to the same publicKey as mint's.

could anyone please help me do it inside a JS module and not through the CLI?


Viewing all articles
Browse latest Browse all 8092

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>