47 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
import { wagmiContract } from './contract'
const client = createPublicClient({
chain: mainnet,
transport: http(),
})
const address = '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC'
// Note: this is a naive example – you should probably use multicall for these
// types of batched reads instead.
const [name, totalSupply, symbol, tokenUri, balance] = await Promise.all([
client.readContract({
...wagmiContract,
functionName: 'name',
}),
client.readContract({
...wagmiContract,
functionName: 'totalSupply',
}),
client.readContract({
...wagmiContract,
functionName: 'symbol',
}),
client.readContract({
...wagmiContract,
functionName: 'tokenURI',
args: [420n],
}),
client.readContract({
...wagmiContract,
functionName: 'balanceOf',
args: [address],
}),
])
export default [
`Contract Address: ${wagmiContract.address}`,
`Name: ${name}`,
`Total Supply: ${totalSupply}`,
`Symbol: ${symbol}`,
`Token URI of #420: ${tokenUri}`,
`Balance of ${address}: ${balance}`,
]