How to integrate with VeritiDAO

This guide will show you how to connect to the VeritiDAO smart contract using ethers.js.

Step-by-step guide

First, set up a provider and connect to the contract. This can be a local Ethereum node, or a service like Infura.

const ethers = require('ethers');

// Setup provider
const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/YOUR-PROJECT-ID');

// Contract ABI and address
const contractABI = [...]; // ABI goes here
const contractAddress = '...'; // Contract address goes here

// Create contract instance
const contract = new ethers.Contract(contractAddress, contractABI, provider);

Replace 'YOUR-PROJECT-ID', contractABI, and contractAddress with your actual Infura project ID, contract ABI, and contract address, respectively. Check the VeritiNFT smart contract address here.

Example 1: Retrieve Metadata

To retrieve metadata for a specific token, use the tokenURI method. This method takes a token ID as an argument and returns a JSON object containing the metadata.

Please note that the tokenURI function returns a data URI, which already includes the JSON object in a base64 encoded format. We need to decode this string and then parse the JSON. Here's how you can do it:

Example 2: Retrieve All Current Listings

To retrieve all current listings, iterate through each token using the totalSupply and tokenByIndex methods:

Example 3: Listen to the Listed Event

To maintain a live feed of all new and updated listings, you can listen to the Listed event using the on method. This allows you to update the metadata for a token in real-time whenever the Listed event is emitted. Here's how you can do it:

Make sure to handle any errors that may occur during the execution of these methods.

Commercial API

VeritiDAO will soon provide a commercial API for retrieving metadata. This service will eliminate the need for users to interact directly with the smart contract, offering a more streamlined and efficient data retrieval process. More information on this upcoming service will be shared in due course.

Last updated