Lab 2
This commit is contained in:
55
scripts/contract-explorer.ts
Normal file
55
scripts/contract-explorer.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import prompts from 'prompts';
|
||||
import { createPublicClient, erc20Abi, http } from 'viem';
|
||||
import { nextChain } from '../chains/next.js';
|
||||
|
||||
const client = createPublicClient({
|
||||
chain: nextChain,
|
||||
transport: http()
|
||||
});
|
||||
|
||||
// you don't have to touch this function, it's already good
|
||||
const readErc20Contract = async (contractAddress: `0x${string}`, func: any, args: any) => {
|
||||
return client.readContract({
|
||||
address: contractAddress,
|
||||
abi: erc20Abi,
|
||||
functionName: func,
|
||||
args: args
|
||||
})
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { contractAddress, accountAddress }:
|
||||
{ contractAddress: `0x${string}`, accountAddress: `0x${string}` } = await prompts([{
|
||||
type: 'text',
|
||||
name: 'contractAddress',
|
||||
message: 'Enter the contract address to explore:',
|
||||
}, {
|
||||
type: 'text',
|
||||
name: 'accountAddress',
|
||||
message: 'Enter the account address:',
|
||||
}]);
|
||||
|
||||
if (!contractAddress || !accountAddress) {
|
||||
console.error('You need to enter both a contract address and an account address.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// you can start coding here
|
||||
// ...
|
||||
|
||||
|
||||
console.log(`Contract address: ${contractAddress}`);
|
||||
console.log(`========================================`);
|
||||
console.log(`Name: ...`);
|
||||
console.log(`Symbol: ...`);
|
||||
console.log(`Decimals: ...`);
|
||||
|
||||
console.log(); console.log(); console.log();
|
||||
|
||||
console.log(`Account address: ${accountAddress}`);
|
||||
console.log(`========================================`);
|
||||
console.log(`Balance: ...`);
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user