Published
Edited
Jun 5, 2022
Insert cell
Insert cell
Insert cell
Insert cell
balances = Promise.all(networks.map(async network => {
return Object.fromEntries([
['Chain', network.name],
].concat(
await Promise.all(['USDC', 'USDT', 'WETH', 'WBTC'].map(async symbol => {
const web3 = new Web3(network.rpcUrl)
if (network[symbol] == 'native') {
return [symbol, await web3.eth.getBalance(address) / 1e18]
} else if (network[symbol]) {
const token = new web3.eth.Contract(abi, network[symbol])
const method = network.name.match(/Oasis/) ? token.methods.totalSupply() : token.methods.balanceOf(address)
const balance = await method.call()
const decimals = await token.methods.decimals().call()
return [symbol, balance / Math.pow(10, decimals)]
} else {
return [symbol, null]
}
}))
))
}))
Insert cell
total = Object.fromEntries(
[['Chain', 'Total']].concat(
['USDC', 'USDT', 'WETH', 'WBTC'].map(symbol =>
[symbol, balances.reduce((sum, chain) => chain.Chain.match(/Oasis/) ? sum : sum+chain[symbol], 0)])))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
networks = FileAttachment("networks@10.csv").csv()
Insert cell
Insert cell
Insert cell
abi = (await fetch('https://cdn.jsdelivr.net/npm/erc-20-abi@latest')).json()
Insert cell
Web3 = require("https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js");
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more