Published
Edited
Mar 9, 2022
Insert cell
Insert cell
Insert cell
Insert cell
provider.getNetwork()
Insert cell
feeData = await provider.getFeeData()
Insert cell
feeHistory = provider.send('eth_feeHistory', [100, "latest", [25, 75]])
Insert cell
TX_COUNT = 1
Insert cell
runTest(TX_COUNT)
Insert cell
resultShow
Insert cell
async function runTest (count) {
const contract = await deployContract(contractCompiled.abi, contractCompiled.bin, signer)
const len = userAddresses.length
const amount = ethers.BigNumber.from(100000)
const txhashes = []
const receipts = []
const balances = {}
const amountsPerUser = {}
const overrides = {
gasLimit: 60000,
// gasPrice: 1,
// maxFeePerGas: "0x9502f90e",
// maxPriorityFeePerGas: "0x9502f900"
// maxFeePerGas: "0x9502f90e", // 2500000014
}
for (let user of userAddresses) {
balances[user] = await contract.balanceOf(user)
amountsPerUser[user] = ethers.BigNumber.from(0)
}

// Send mint transaction
for (let i = 0; i < count; i++) {
const user = userAddresses[i % len]
const maxPriorityFeePerGas = 250000000 + Math.floor(Math.random() * 10000000)
const maxFeePerGas = maxPriorityFeePerGas + Math.floor(Math.random() * 10000)
const _overrides = {
...overrides,
maxFeePerGas,
maxPriorityFeePerGas,
}
let receipt = await contract.mintFor(amount, user, _overrides)
amountsPerUser[user] = amountsPerUser[user].add(amount)
txhashes.push(receipt)
}
console.log('txhashes', txhashes.length)
mutable resultShow = 'tx: ' + txhashes.length + '\n'

// Check mint transaction, get receipt
for (let i = 0; i < count; i++) {
const user = userAddresses[i % len]
let receipt = txhashes[i]
receipt = await receipt.wait()
receipts.push(receipt)
const stat = `block ${receipt.blockNumber} gasUsed ${receipt.gasUsed.toString()} ; cumulativeGasUsed ${receipt.cumulativeGasUsed.toString()} ; effectiveGasPrice ${receipt.cumulativeGasUsed.toString()}`
mutable resultShow += stat + '\n'
console.log(stat)
// console.log('receipt', receipt);
}

// Check token balance
for (let i in userAddresses) {
const user = userAddresses[i]
const balance = await contract.balanceOf(user)
const expectedBalance = balances[user].add(amountsPerUser[user])
if (!balance.eq(expectedBalance)) throw new Error(`User ${i}: Balance ${balance} not equal to ${expectedBalance}`)
}
return receipts;
}
Insert cell
async function deployContract(abi, bytecode, signer) {
const factory = new ethers.ContractFactory(abi, bytecode, signer)
const contract = await factory.deploy(new ethers.BigNumber.from("0x8ac7230489e80000"), 18, "Token", "TKN");
return contract;
}
Insert cell
Insert cell
RPC_URL = "http://localhost:8545"
Insert cell
Insert cell
Insert cell
Insert cell
provider = {
return new ethers.providers.JsonRpcProvider(RPC_URL)

// Metamask
// const provider = new ethers.providers.Web3Provider(window.ethereum)
// await provider.send("eth_requestAccounts", []);
// return provider;
}
Insert cell
Insert cell
Insert cell
ethers = require('ethers@5.5.4/dist/ethers.umd.js')
Insert cell
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