Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using ethersJs instead of web3 #49

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions helper-hardhat-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ const autoFundCheck = async (contractAddr, networkName, linkTokenAddress, additi
const LinkToken = await ethers.getContractFactory("LinkToken")
const linkTokenContract = new ethers.Contract(linkTokenAddress, LinkToken.interface, signer)
const balanceHex = await linkTokenContract.balanceOf(signer.address)
const balance = await web3.utils.toBN(balanceHex._hex).toString()
const balance = await ethers.BigNumber.from(balanceHex._hex).toString()
const contractBalanceHex = await linkTokenContract.balanceOf(contractAddr)
const contractBalance = await web3.utils.toBN(contractBalanceHex._hex).toString()
const contractBalance = await ethers.BigNumber.from(contractBalanceHex._hex).toString()
if (balance > amount && amount > 0 && contractBalance < amount) {
//user has enough LINK to auto-fund
//and the contract isn't already funded
Expand Down
11 changes: 8 additions & 3 deletions tasks/balance.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
const { ethers } = require("ethers");

const network = process.env.NETWORK;
const provider = ethers.getDefaultProvider(network)

task("balance", "Prints an account's balance")
.addParam("account", "The account's address")
.setAction(async taskArgs => {
const account = web3.utils.toChecksumAddress(taskArgs.account)
const balance = await web3.eth.getBalance(account)
const account = ethers.utils.getAddress(taskArgs.account)
const balance = await provider.getBalance(account)

console.log(web3.utils.fromWei(balance, "ether"), "ETH")
console.log(ethers.utils.formatEther(balance), "ETH")
})

module.exports = {}
2 changes: 1 addition & 1 deletion tasks/withdraw-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ task("withdraw-link", "Returns any LINK left in deployed contract")
const LinkToken = await ethers.getContractFactory("LinkToken")
const linkTokenContract = new ethers.Contract(linkTokenAddress, LinkToken.interface, signer)
const balanceHex = await linkTokenContract.balanceOf(contractAddr)
const balance = await web3.utils.toBN(balanceHex._hex).toString()
const balance = await ethers.BigNumber.from(balanceHex._hex).toString()
console.log('LINK balance of contract: ' + contractAddr + " is " + balance / Math.pow(10,18))

if (balance > 0) {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/APIConsumer_int_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ skip.if(developmentChains.includes(network.name)).

//Now check the result
const result = await apiConsumer.volume()
console.log("API Consumer Volume: ", new web3.utils.BN(result._hex).toString())
expect(new web3.utils.BN(result._hex)).to.be.a.bignumber.that.is.greaterThan(new web3.utils.BN(0))
console.log("API Consumer Volume: ", new ethers.BigNumber.from(result._hex).toString())
expect(new ethers.BigNumber.from(result._hex).toString()).to.be.a.bignumber.that.is.greaterThan(new ethers.BigNumber.from(0).toString())
})
})
4 changes: 2 additions & 2 deletions test/integration/RandomNumberConsumer_int_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ skip.if(developmentChains.includes(network.name)).
await new Promise(resolve => setTimeout(resolve, 30000))

const result = await randomNumberConsumer.randomResult()
console.log("VRF Result: ", new web3.utils.BN(result._hex).toString())
expect(new web3.utils.BN(result._hex)).to.be.a.bignumber.that.is.greaterThan(new web3.utils.BN(0))
console.log("VRF Result: ", new ethers.BigNumber.from(result._hex).toString())
expect(new ethers.BigNumber.from(result._hex).toString()).to.be.a.bignumber.that.is.greaterThan(new ethers.BigNumber.from(0).toString())
})
})
4 changes: 2 additions & 2 deletions test/unit/PriceConsumerV3_unit_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ skip.if(!developmentChains.includes(network.name)).

it('should return a positive value', async () => {
let result = await priceConsumerV3.getLatestPrice()
console.log("Price Feed Value: ", new web3.utils.BN(result._hex).toString())
expect(new web3.utils.BN(result._hex).toString()).to.be.a.bignumber.that.is.greaterThan(new web3.utils.BN(0))
console.log("Price Feed Value: ", new ethers.BigNumber.from(result._hex).toString())
expect(new ethers.BigNumber.from(result._hex).toString()).to.be.a.bignumber.that.is.greaterThan(new ethers.BigNumber.from(0).toString())
})
})