-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_smart_contract.js
31 lines (24 loc) · 1.12 KB
/
read_smart_contract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { ethers } = require("ethers")
const INFURA_ID = 'd0c4db9e7e0041c3bace607d958c5e1c'
const provider = new ethers.providers.JsonRpcProvider(`https://mainnet.infura.io/v3/${INFURA_ID}`)
const ERC20_ABI = [
"function name() view returns (string)",
"function symbol() view returns (string)",
"function totalSupply() view returns (uint256)",
"function balanceOf(address) view returns (uint)",
]
const address = '0x6B175474E89094C44Da98b954EedeAC495271d0F' //DAI Contract
const contract = new ethers.Contract(address, ERC20_ABI, provider)
const main = async () => {
const name = await contract.name()
const symbol = await contract.symbol()
const totalSupply = await contract.totalSupply()
console.log(`Reading from ${address}\n`)
console.log(`"name : ", ${name}`)
console.log(`Symbol : ${symbol}`)
console.log(`Total Supply : ${totalSupply}\n`)
const balance = await contract.balanceOf('0x6c6Bc977E13Df9b0de53b251522280BB72383700')
console.log(`Balance Returned: ${balance}`)
console.log(`Formatted Balance: ${ethers.utils.formatEther(balance)}\n`)
}
main()