How to update NFT metadata for drop contract via thirdweb SDK
In this guide, we will explore how to update the NFT metadata using code and the Thirdweb SDK.
This method only works for our prebuilt NFT Drop & Edition Drop contracts
Here is the code to use to update the NFT Metadata
import { defineChain } from "thirdweb/chains";
import { privateKeyToAccount } from "thirdweb/wallets";
import { sendTransaction, getContract, createThirdwebClient } from "thirdweb";
import { updateMetadata } from "thirdweb/extensions/erc721"; // for nft drop
import { updateMetadata } from "thirdweb/extensions/erc1155"; // for edition drop
export async function main() {
const client = createThirdwebClient({
secretKey: "",
});
const account = privateKeyToAccount({
client,
privateKey: "",
});
const contract = getContract({
client,
chain: defineChain(80002),
address: "",
});
const transaction = updateMetadata({
client,
contract,
targetTokenId: 0n,
newMetadata: {
name: "this is the new nft name",
description: "...",
image: "new image uri",
// ...
},
});
try {
const transactionResult = await sendTransaction({
transaction: tx,
account: account,
});
} catch (e) {
console.log(e)
}
}
main();
Can’t get this working? If you’ve followed the above and still have issues, contact our support team for help.
Did this answer your question?
😞
😐
🤩