New answers tagged

1 vote
Accepted

How to instantiate contract instances with ethers.js and alchemy-sdk

Try this example of using the alchemy-sdk to connect to eth mainnet to load a contract instance. I think the key difference is that you should use await alchemy.config.getProvider() instead of what ...
user avatar
1 vote

How to instantiate contract instances with ethers.js and alchemy-sdk

instead of passing alchemy.core, pass return value of this const ethersProvider = await alchemy.config.getProvider() final: const CompoundorContract = new ethers.Contract( CONSTANTS.ADDRESSES....
user avatar
  • 51
0 votes

Where to find Uniswap contract addresses on Goerli testnet

Just set your wallet for goerli network, go to app.uniswap.org, click "Pool" and "+ New Position" - then you can see the available tokens - I see ETH, UNI and WETH and you can '...
user avatar
1 vote
Accepted

Calling a function with multiple arguments in ethers returns Error: missing argument

You pass parameters like this: const ethPriceData = await administrativeSidechainContract.getUniversalConversionRate("1", "0x....") If you want to send ether, set gasLimit etc ...
user avatar
0 votes

Is it possible to log how much gas was used during hardhat/ethers transaction?

@kornelHub answer works except you might need to pay attention to the property of gas used. There are two properties explain the used gas amount, one is gasUsed, and another is cumulativeGasUsed, as ...
user avatar
0 votes

Chainlink Keepers - getting "InvalidConsumer"

as done manually for testnet (Look into https://youtu.be/rdJ5d8j1RCg by chainlink) , we have to create a VRFCoordinatorV2 (VRFCoordinatorV2Mock in case of local testing), fund it and then have to add ...
user avatar
0 votes

CALL_EXCEPTION when calling a simple view function with ethers.js, but not in my hardhat test

Hii even I ran out in the same issue...The problem with me was My metamask was connected to another network. I switched to hardhat network in metamask it worked.
user avatar
1 vote

How to detect if user rejects transaction

Could you not use a try catch? Then in the catch you can watch for the 4001 which is specifically used for user requests denied.
user avatar
0 votes

Ether.js works fine on desktop but not with metamask app (android/ios)

Because window.ethereum does not exist on mobile. it's only available on desktop web browsers. i believe that there are several ways: 1- Try to connect to Metamask on mobile via wallet connect. 2- if ...
user avatar
  • 51
1 vote

Chainlink Keepers - getting "InvalidConsumer"

I had this issue as well and the solution for me was..edit your deploy-raffle js using the following steps 1 make the the variable that holds "VRFCoordinatorV2Mock" contract a global ...
user avatar
  • 11
0 votes

Assigning roles to addresses after off-chain KYC verification

I would suggest to use off-chain signatures, signed by a wallet your marketplace controls and then verified onchain. I've just given a similar answer to this thread: https://stackoverflow.com/a/...
user avatar
0 votes

hardhat deploy with specific account

Can you try this? [theDefaultDeployer, acc1] = await ethers.getSigners(); // we will not use the "theDetaultDeployer" in what follows: const MyContract = await ethers.getContractFactory(&...
user avatar
0 votes

Chainlink Keepers - getting "InvalidConsumer"

I have the exact same issue. After debugging the code, I found we have to add the Raffle contract's address to VRFCoordinatorV2Mock's consumers by add the following code to your deploy file (for me it ...
user avatar
  • 1
0 votes

Ethers.js signTransaction with LedgerSigner doesn't work on Polygon (transaction.chainId/signature.v mismatch)

For those who facing the same problem, I finally manage to make it work by following this post https://github.com/ethers-io/ethers.js/issues/1365#issuecomment-918817511
user avatar
1 vote

How do I get a signed transaction without sending it to the chain?

You can create a transaction (without sending it) like this using web3js: const web3Provider = new Web3( new Web3.providers.Web3Provider( ENDPOINT ) ) web3Provider.eth....
user avatar
  • 426
0 votes

Cannot interact with deployed contract - negative hex string

try to add below code after .deploy() call: await contract.deployed(); for example: const FirstContract = await ethers.getContractFactory("FirstContract"); const firstContract = await ...
user avatar
  • 51
0 votes

Ethers and Web3-React: Cannot estimate gas when trying to connect with contracts deployed on testnet and using Alchemy as node provider

you should put gasLimit either manually or dynamically in last argument of SC method call. const tx = await farmContract.depositEth({ gasLimit: <estimate number>, }) for getting the gas ...
user avatar
  • 51
0 votes

Incorrect Gaslimit estimation for transaction

Gas estimation gets complicated if there are multiple execution paths. The way hardhat network implements eth_estimateGas is first it passes block gas limit to get gas used, then tries with gas used ...
user avatar
  • 1,251
0 votes

ecrecover returns incorrect address

I solved this by changing signature generation on my frontend with ethers.utils.solidityKeccak256() method (twice for functions in this example, if check needed). It seems like ethers.utils....
user avatar
0 votes

TypeError: ethers.getContractFactory is not a function

you may need to change require from use hardhat-toolbox to hardhat-walffle as per may existing you've got these below line in your hardhat.config.js require("@nomicfoundation/hardhat-toolbox"...
user avatar
  • 1
0 votes

Chainlink Keepers - getting "InvalidConsumer"

I have the exact same issue. And I have checked what Patrick said about creating a new costumer. It should have been created when running the .createSubscription on the Deploy function, no ? module....
user avatar
  • 1
0 votes

How to reference a contract's library function in hardhat testing

To reference them use the library name, like this PriceConverter.getConversionRate. Then fill the parameters as needed AggregatorV3Interface _priceFeed; // required price feed function bar() public ...
user avatar
  • 29.5k
1 vote
Accepted

Hardhat deploying multiple contracts to one address

These contracts will not be deployed at the same address - each address only contains a maximum of one contract. Let's break down what's happening here. You're deploying one contract using Ethers (the ...
user avatar
0 votes

Event listener firing multiple times

may you can use simple rpc provider rather sockets I was having same issue I resolved it by using rpc provider infura Provider = new ethers.providers.JsonRpcProvider(`https://polygon-mumbai.infura.io/...
user avatar
0 votes

How to get ABI of deployed contract using ethersjs in hardhat?

If you are deploying by command line, you can read from the file where is previously builded, in the case of hardhat there is a example: const fs = require("fs") const path = require("...
user avatar
3 votes
Accepted

Why are all ethersjs & web3js calls to BSC network failing?

Try changing provider. I use Chainstack and it works great. Follow these steps to sign up on Chainstack, deploy a node, and find your endpoint credentials: Sign up with Chainstack. Deploy a node. ...
user avatar
  • 366
0 votes

How to get private and public key from ethers.provider.getSigner()

You can only access the public and private key if you built the signer from a mnemonic or a private key. The relevant fields are on the signer type Wallet in ethers. Specifically, wallet.publicKey and ...
user avatar
  • 170
1 vote

Send function of ethers.js

The send method sends a raw JSON RPC call, where the first parameter is the RPC method and the second parameter is an array of arguments specific to the method. In your example it is calling a RPC ...
user avatar
  • 170
1 vote

ethers is not defined

In addition to the accepted answer, ensure that hardhat.config.js is included in your tsconfig.json.
user avatar
0 votes
Accepted

HardhatError: HH17: The input value cannot be normalized to a BigInt: Unsupported type undefined

You should have await inside expect statement. You are getting a Promise which cannot be parsed as bigInt
user avatar
  • 16
0 votes

Truffle vs Hardhat vs Ethers vs Web3 what to choose for a beginner?

Truffle, Hardhat, Brownie, Foundry (etc) are smart contract development frameworks. For making stuff you deploy to the blockchain. Web3.js and Ethers.js are javascript libraries mainly used for ...
user avatar
  • 31
0 votes

Truffle vs Hardhat vs Ethers vs Web3 what to choose for a beginner?

There are use-cases for each one. Il try give you some simplifications how to understand each one of them. Truffle: Use it to setup a project that will interact with smart contracts and blockchain. It ...
user avatar
1 vote

Storage of private key for etherjs app

Storing private keys is always a pain, since you need them in plain text to sign transactions. Take a look at what owasp has to say about storing: Storage Developers must understand where ...
user avatar
2 votes

In ethers.js how to deal wait()?

For ethers.js v5: let receipt = await tx.wait()
user avatar
0 votes

How to estimate gas Price using Ethers.js prior to sending the transaction?

I am not sure i get it right but if you want to estimateGas you send contract address methodId of required function any amount to test and data is "0x" + first 4 bytes of keccak hash of the ...
user avatar
0 votes

ethers.queryFilter returns TypeError: Cannot read properties of undefined (reading 'map')

The problem was the fork. Since I didn't specify a block number for the queryFilter it tried to gather info from the genesis block but it has only the last 128 block available to query from.
user avatar
  • 1,214
0 votes

Code to convert crypto wallet passphrase to 32 byte private key

You can simply try out the code below const ethers = require('ethers') const randomMnemonic = ethers.Wallet.createRandom().mnemonic; console.log('randomMnemonic',randomMnemonic) const wallet = ethers....
user avatar
1 vote

How to mint NFT using ethers.js?

First, make sure that the contract address is right. Next, try removing gasPrice, gasLimit and nonce from your transaction and let Metamask calculate those for you. Just try to execute the transaction ...
user avatar
  • 426
3 votes

Is it possible to track how many event listener does the specific smart contract have?

Umh, no. Each event listener uses a node to read its data. The closest thing you can do is track nodes with something like https://ethernodes.org/ , but you won't have much knowledge about what the ...
user avatar
0 votes
Accepted

Recover Parameter from given signed message

Just found out by myself... Here the answer if someone stuck at the same problem: ethers.utils.hashMessage() Can take a string or binary datas... from Doc(https://docs.ethers.io/v5/api/utils/hashing/...
user avatar
  • 231
0 votes

Error handling with ethers.js

maybe call a cheaper ethereum method. provider.getNetwork();
user avatar
3 votes

How to call a contract function/method using ethersjs

July 2022, ethers.js 5.6, TypeScript. An example that prints USDT token total supply on Mainnet. Metamask: const ethereum = (window as any).ethereum; const accounts = await ethereum.request({ ...
user avatar
0 votes

How to show smart contract data when user has a wallet installed but is not logged in?

In this case, I would set the default provider as the RPC provider, then check to see if window.ethereum exists. If it does exist, then we can try to use it as a provider and list accounts available ...
user avatar
0 votes

Ethers Provider CORS error with JsonRPCProvider inside of react application

The solution was to move this to server side and have the client call the server.
user avatar
1 vote
Accepted

Is this code deploying 2 different contracts to the same address?

We can see that UnstoppableLender has a constructor argument of a ERC20 token for it constructor. When we pass the address of the newly deployed token to the to the deploy function, this is the value ...
user avatar
1 vote

Ethers-EIP712 wont work with strings

You need to abi.encodePacked and keccak256 the string first. function verify(forwardData calldata data, bytes calldata signature) internal view returns (address) { return _hashTypedDataV4( ...
user avatar
  • 71
-1 votes

how to test if array contains any value?

Your people array is public, you can call await simpleStorage.people.length; directly in test instead of creating the function numOfPeople() in the contract as mentioned in the previous answer
user avatar
  • 74
-1 votes

how to test if array contains any value?

You can simply check that by an if-else statement with the array.length method: if (peopleArray.length === 0) { return console.log("Array is empty") } else { return console.log("...
user avatar
  • 135
0 votes
Accepted

how to test if array contains any value?

i need to create a function that exposes this information separately, e.g.: function numOfPeople() public view returns (uint256) { return people.length; } When calling this function, if it returns ...
user avatar
0 votes

How to listen to contract events using ethers.js?

try { const tokenObject = { ImageIPFS: data.eventcard.picture_ipfs, metaData: { EventName: data.eventcard.name, Description: data....
user avatar
  • 1

Top 50 recent answers are included