Update NFT metadata
A TokenUpdateNftsTransaction updates the metadata property of non-fungible tokens (NFTs) on the Hedera network. The transaction requires signing with the metadata key and will fail otherwise. The new metadata must be a valid byte array and is limited to 100 bytes. All transactions are recorded on the network, providing an auditable history of changes. The metadata key allows updates to existing NFTs in a collection; if no value is provided for a field, it remains unchanged.
🚨 Metadata keys, like other token keys, must be set during the token creation. If metadata keys are not set when the token is created, they cannot be added later, and you won't be able to update the token's metadata.
Token ID
The ID of the NFT to update.
Serial Numbers
The list of serial numbers to be updated.
Metadata
The new metadata of the NFT(s).
Transaction Signing Requirements
Metadata key is required to sign.
Transaction fee payer account key.
Transaction Fees
Please see the transaction and query fees table for the base transaction fee.
Please use the Hedera fee estimator to estimate your transaction fee cost.
Methods
setTokenId(<tokenId>)
TokenID
Required
setSerialNumbers(<[int64]>)
List<int64>
Required
setMetadata(<bytes>)
bytes
Optional
// Create the transaction
TokenUpdateNftsTransaction tokenUpdateNftsTx = new TokenUpdateNftsTransaction()
.setTokenId(tokenId)
.setSerialNumbers(nftSerials)
.setMetadata(newMetadata)
.freezeWith(client);
// Sign the transaction and execute it
TransactionReceipt tokenUpdateNftsResponse = tokenUpdateNftsTx.sign(metadataKey)).execute(client);
// Get receipt for update nfts metadata transaction
TokenUpdateNftsReceipt tokenUpdateNftsReceipt = tokenUpdateNftsResponse.getReceipt(client);
// Get the transaction consensus status
Status transactionStatus = tokenUpdateNftsReceipt.status;
// Print the token update metadata transaction status
System.out.println("Token metadata update status: " + transactionStatus);
//v2.32.0// Create the transaction
const tokenUpdateNftsTx = await new TokenUpdateNftsTransaction()
.setTokenId(tokenId)
.setSerialNumbers([nftSerials])
.setMetadata(newMetadata)
.freezeWith(client);
// Sign and execute the transaction with the metadata key
const tokenUpdateNftsResponse = await (
await tokenUpdateNftsTx.sign(metadataKey)
).execute(client);
// Get receipt for token update nfts metadata transaction and log the status
const tokenUpdateNftsReceipt = await tokenUpdateNftsResponse.getReceipt(client);
// Log the token nft update transaction status
console.log(
`Token metadata update status: ${tokenUpdateNftsTxReceipt.status.toString()}`,
);
//v2.45.0//Create the transaction and freeze for manual signing
tokenUpdateNftsTransaction, err := hedera.NewTokenUpdateNftsTransaction().
SetTokenID(tokenId).
SetSerialNumbers(nftSerials).
SetMetadata(newMetadata).
FreezeWith(client)
if err != nil {
panic(err)
}
// Sign and execute the transaction
tokenUpdateNftsResponse, err := tokenUpdateNftsTx.Sign(metadataKey).Execute(client)
if err != nil {
panic(err)
}
// Request the receipt of the transaction
receipt, err :=tokenUpdateNftsResponse.GetReceipt(client)
if err != nil {
panic(err)
}
// Print the token update metadata transaction status
fmt.Printf("Token metadata update status: ", receipt.Status)
//v2.37.0// Create the transaction
let token_update_nfts_tx = TokenUpdateNftsTransaction::new()
.token_id(token_id)
.serials(vec![nft_serial as i64])
.metadata(new_metadata)
.freeze_with(&client)?;
// Sign the transaction and execute it
let token_update_nfts_response = token_update_nfts_tx
.sign(metadata_key)
.execute(&client).await?;
// Get receipt for update nfts metadata transaction
let token_update_nfts_receipt = token_update_nfts_response.get_receipt(&client).await?;
// Get the transaction consensus status
let transaction_status = token_update_nfts_receipt.status;
// Print the token update metadata transaction status
println!("Token metadata update status: {:?}", transaction_status);
// v0.34.0FAQs
Contributors: MilanWR
Last updated
Was this helpful?