2022 Developer Survey is open! Take survey.
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 ...
user avatar
  • 4,934
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 ...
user avatar
  • 119
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 ...
user avatar
  • 4,934
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 ...
user avatar
  • 4,934
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 ...
user avatar
  • 61
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.
user avatar
  • 180
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 ...
user avatar
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: ...
user avatar
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....
user avatar
  • 1,236
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 (...
user avatar
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 ...
user avatar
  • 1,236
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 ...
user avatar
  • 417
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....
user avatar
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 ...
user avatar
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.
user avatar
  • 11
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( "...
user avatar
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.
user avatar
  • 26

Only top scored, non community-wiki answers of a minimum length are eligible