I want to add metadata on solana nft.
export const createToken = async () => {
let bs58 = require("bs58");
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const bs = bs58.decode(secretKey);
const wallet = Keypair.fromSecretKey(bs); // get wallet keypair
// TokenAccount
const mint = await createMint(
connection,
wallet,
wallet.publicKey,
null,
0, // if value is 0, means non-fungible token
undefined,
{},
TOKEN_PROGRAM_ID,
);
console.log(mint.toBase58());
// TokenMintAccount
const associatedTokenAccount = await getOrCreateAssociatedTokenAccount(
connection,
wallet,
mint,
wallet.publicKey,
);
await mintTo(connection, wallet, mint, associatedTokenAccount.address, wallet, 1);
let transaction = new Transaction().add(
createSetAuthorityInstruction(mint, wallet.publicKey, AuthorityType.MintTokens, null),
);
const trans = await sendAndConfirmTransaction(connection, transaction, [wallet]);
connectWithMetaplex(wallet, mint.toBase58());
};
export const connectWithMetaplex = async (wallet, tokenMintAccount) => {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
// const metaplex = Metaplex.make(connection).use(keypairIdentity(wallet)).use(bundlrStorage());
const mx = Metaplex.make(connection);
await mx.nfts().findByMint(new PublicKey(tokenMintAccount));
await mx.nfts().uploadMetadata({
name: "JERRY NFT",
description: "JERRY'S NFT 1",
});
};
I refer https://github.com/metaplex-foundation/js#uploadMetadata
I think there is no connection between metadata and my token address.
is there anyway make them connected?
export const createToken = async () => {
let bs58 = require("bs58");
const bs = bs58.decode(secretKey);
const wallet = Keypair.fromSecretKey(bs); // get wallet keypair
connectWithMetaplex(wallet);
};
export const connectWithMetaplex = async wallet => {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
const metaplex = Metaplex.make(connection).use(keypairIdentity(wallet));
const { uri } = await metaplex
.nfts()
.uploadMetadata({
name: "JERRY NFT",
description: "JERRYS FIRST NFT",
})
.run();
const { nft } = await metaplex
.nfts()
.create({
uri: uri,
name: "JERRY NFT",
sellerFeeBasisPoints: 100,
})
.run();
console.log(nft);
};
update code