AI Network
  • What is AI Network
  • AIN Blockchain
    • Architecture
      • Design Principles
      • Event-driven Architectures
      • Blockchain Database
        • States
          • State Types
          • Operations
          • Predefined Structures
        • Rules and Owners
          • Rule Configs
          • Owner Configs
        • Functions
          • Built-in Functions
      • Instant Execution, and Eventual Consistency
      • Network ID and Chain ID
      • Transactions
        • Structure
        • Nonce
        • Read Concern
        • Propagation
      • Block Structure
      • Account and Keys
      • Consensus
      • Scalability
      • Apps
    • Developer Guide
      • Quick Start
      • AI Network Products
        • AI Network Worker
        • AI Network Insight
        • Testnet Server Node
        • Ainize Trigger
          • Project user
          • Project deployer
          • Why do we have to use Ainize Trigger?
      • Token Bridge
      • Trouble Shooting
    • Developer Reference
      • Blockchain API
        • JSON RPC API
        • Node Client API
      • Blockchain SDK
        • ain-js
        • ain-py
      • Validators
    • Staking
  • AIN DAO
    • What is AIN DAO
      • Runo (Run Your Node)
      • GPU Sponsorship Program
    • Onboarding & Participation
    • Governance
    • Tokenomics
      • AI Network Tokenomics
      • AINFT Tokenomics
  • AI Agents
    • AINFT
    • AINFT Factory
    • AINFT Projects
      • 🍳MiniEggs
      • 🦈Baby Shark
      • 🛸Soul Fiction
      • 🎻NFT Classics Society
    • Developer Reference
      • Ainft-Js
      • AINFT tutorial
        • Create AINFT object and Mint
        • Transfer AINFT
        • Set metadata of AINFT
        • Search and Retrieve AINFT
  • AIN Wallet
    • What is AIN Wallet?
    • AIN Wallet API
  • PROPOSAL DOCUMENTS
    • AIN Improvement Memos (AIMs)
    • AIN Improvement Proposals (AIPs)
Powered by GitBook
On this page

Was this helpful?

  1. AI Agents
  2. Developer Reference
  3. AINFT tutorial

Set metadata of AINFT

This tutorial describes how to update AINFT’s metadata with ainft-js. If you don’t have AINFT, See AINFT tutorial - Create & Mint.

Set metadata

Only AINFT object owner can update metadata of each token. Metadata is configured as JSON format.

const AinftJs = require('@ainft-team/ainft-js').default;

const privateKey = 'AINFT_OBJECT_OWNER_PRIVATE_KEY';
const config = {
  ainftServerEndpoint: '<https://ainft-api-dev.ainetwork.ai>',
  ainBlockchainEndpoint: '<https://testnet-api.ainetwork.ai>',
}
const ainftJs = new AinftJs(privateKey, config);

const ainftObjectId = '0x6c4605D7a3abAd19f9BbA986746aDF9fFCBE6f9A';
const tokenId = '1';
const metadata = {
	name: 'my first token',
	image: '<https://miro.medium.com/v2/resize:fit:2400/1*GWMy0ibykACFKS_rRxFlcw.png>'
}

const main = async () => {
	try {
		const ainftObject = await ainftJs.nft.get(ainftObjectId);
	  const ainft = await ainftObject.getToken(tokenId);
	  const result = await ainft.setMetadata(metadata);
	  console.log(result);
	} catch(error) {
		console.log(error);
	}
}

main();

// {
//   tx_hash: '0x9009753dcb212a0b4c898022e38afd8d5a02200ef6429a4e4048ddf9c0e6a5a1',
//     result: {
//     gas_amount_total: { bandwidth: [Object], state: [Object] },
//     gas_cost_total: 0,
//       func_results: {
//       '0x6c4605D7a3abAd19f9BbA986746aDF9fFCBE6f9A_trigger_metadata': [Object]
//     },
//     code: 0,
//       bandwidth_gas_amount: 1,
//         gas_amount_charged: 0
//   }
// }

You can check if transaction is completed using tx_hash in insight.

You can check updated metadata through the insight database.

PreviousTransfer AINFTNextSearch and Retrieve AINFT

Last updated 1 year ago

Was this helpful?

https://testnet-insight.ainetwork.ai/