3
votes
Accepted
Comparing ethers BigNumber does not work
Try like this :
expect(totalSupply.eq(BigNumber.from("4")).to.equal(true);
This is because to.equal internally uses the strict equality check === which on Objects only returns true if the ...
3
votes
Estimate gas price with ethers.js
As of 2022 you should use getFeeData() since getGasPrice() has been deprecated. This accounts for network fee changes introduced in EIP-1559. The creator of Ethers.js talks about this in the above ...
3
votes
How do you check if a contract has a function using Ethers.js?
While other answers are correct, I think they can be improved as they only check for inclusion of a specific function selector in the bytecode which is not the same as checking if the jump table ...
2
votes
Accessing storage of a map of a map
To do it that way, you must know what to look for, meaning that you should know beforehand some combinations of tokens addresses to compute the pair address for. Or, as @longhuynh suggested, you could ...
2
votes
Accepted
Why does a view function cost gas?
You are calling getListedItemsOf method from your frontend. Shouldn't you be calling getItemsOf like you have posted in your question?
These two methdos have different stateMutability in the provided ...
1
vote
Accepted
How to format hex string to solidity address?
After a small investigation the ethers.utils.getAddress function formats the address as desired.
1
vote
Is the key generated below valid and cryptographically secure?
I don't think there is a way to generate fully random keys with regular hardware. All the keys you generate are pseudo-random - but in most of the cases that's just fine.
Nothing stops you from ...
1
vote
Accepted
Metamask not switching chain to Rinkeby testnet
I think you mixed up the functions for "switching" and for "adding" a network. The function to switch network should only have to pass the chainId.
This is what my code looks like:
...
1
vote
Only getting 'Promise { <pending> } when calling getPair on the Quickswap Factory contract with ethers.js?
You need to await for getPairAddr as well, since it's async - meaning returns a Promise.
Change this -
const pairAddr = CC.getPairAddr(FACTORY, DAI, WETH);
to this -
const pairAddr = await CC....
1
vote
Accessing storage of a map of a map
I don't think it is possible to iterate through the value of a mapping, unless you store an array of keys for that mapping. Smart contract's storage layout for dynamic mapping is quite complicated (...
1
vote
How to get ERC standard of tokens in a transaction from transaction hash?
Etherscan index the whole blockchain and track all ERC20, ERC721 and others, so once a transaction interacts with one of these addresses, they already know it's a token.
If you haven't tracked and ...
1
vote
ethers contract call for value of state variable reverts with "missing revert data"
In case anyone comes across this trying to hunt down a reason for "missing revert data in call exception" in this case it was the result of calling a function that existed in the ABI I was ...
1
vote
How do you check if a contract has a function using Ethers.js?
First thing, you'd want to fetch the smart contract's deployed bytecode as follows:
const provider = new ethers.providers.InfuraProvider(NETWORK, INFURA_API_KEY);
const bytecode = await provider....
1
vote
How do you check if a contract has a function using Ethers.js?
If you do not have an ABI you can do the following flaky check
Get the contract bytecode using web3.eth.getCode()
Check if the bytecode contains 32-bit Solidity function selector
Note that ...
1
vote
Error: insufficient funds for intrinsic transaction cost on Ropsten
I had a similar problem with the Hello World tutorial on Ethereum.org. Turns out, if you switch your test network from ropsten to goerli, this problem goes away.
1
vote
Impersonating a contract when calling another in tests using ether.js
Complementing Ahmed Ihsan Tawfeeq:
With hardhat there is a easy way to impersonate a contract, this is the code to to that:
const ContractFactory = await ethers.getContractFactory(
"...
1
vote
Accepted
How to retrieve multiple values returned from solidity with ether.js?
const result = await contractInstance.yourFunction();
const {0: variable_1, 1: variable_2} = result;
Reference: https://blockheroes.dev/js-read-multiple-returned-values-solidity/
Hope it helps.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ethers.js × 707solidity × 177
web3js × 156
hardhat × 100
javascript × 75
metamask × 62
react × 53
uniswap × 41
transactions × 34
events × 33
nodejs × 32
erc-20 × 27
ether × 27
etherscan × 23
bsc × 23
blockchain × 21
testing × 19
go-ethereum × 18
contract-invocation × 18
web3-providers × 18
gas × 17
ethereumjs × 17
contract-deployment × 15
contract-development × 14
dapps × 14