New answers tagged

0 votes

Call to contract doesn't work when sending a merkle proof (using ethers & JS)

Fixed it: By taking out the comma in the end of the ethers.utils.parseEther((0.01 * mintAmount).toString()),}); That last comma, now it looks like this: const response = await contract.mint(...
user avatar
  • 1
0 votes

Uncaught TypeError: Cannot read properties of undefined (reading 'getInfo') at index2.js:20:20

The contract property you are refering to does not exists. But Contract does (capital c). So change this: mycontract = new web3.eth.contract(abi, contractAddress); to: mycontract = new web3.eth....
user avatar
0 votes

UNIT Test Error: No Contract deployed with name Raffle

I found the answer.The error was, This line module.exports.tags = ['all', 'mocks']; was inside the deploy script's curly brackets...
user avatar
0 votes

TypeError: Cannot read property 'length' of undefined - While deploying using hardhat

Thank you Patrick and Sharma. I struggled last few days with the above issue. Now it's resolved. By the way, the video course created by Partick is awesome. Thank you again @PatrickAlphaC.
user avatar
0 votes

Error: chainId address mismatch

i found the answer i have been struggling with this for a week! i just changed the Network Id in the ganache to 1337! and it got through!!! Awesome!
user avatar
0 votes

Differences between .deploy() and deployed() methods

From another view point, deployed() is just waveContract.wait() which is just another function call to wait for some block confirmations
user avatar
0 votes

Web3 create account from mnemonic + passphrase

you can create a wallet & restore from mnemonic with ethers: this is updated code const ethers = require("ethers"); const wallet = ethers.Wallet.createRandom(); console.log("...
user avatar
0 votes

Hardhat - How to interact with a deployed contract?

Both getContractAt and attach work for me: I will share the code. this.CollectionMinter = await ethers.getContractFactory("CollectionMinter") this.CollectionMinter = await this....
user avatar
0 votes

Does Smart Contract pay gas fees in this case?

Whoever initiates the transaction pays for the transaction fees. This is usually the end user interacting with the smart contract, but could be the smart contract in some cases of on-chain automation ...
user avatar
0 votes
Accepted

Flashloan Arbitrage error 'SafeERC20: low-level call failed'

So I figured it out theIERC20 token; part of the smart contract had nothing to refer to so I wasn't approving anything
user avatar
  • 107
1 vote

How can I batch execute multiple Gnosis Safe transactions via js/ts?

You can use the MultiSend contract to batch execute execTransaction calls. https://github.com/safe-global/safe-contracts/blob/main/contracts/libraries/MultiSend.sol
user avatar
  • 616
0 votes

web3modal error during Wallet Connect function for web3 in javascript

Ok, I've tried your code and you're calling the connect method of web3Modal in const instance = await web3Modal.connect(); but you declare it some lines later in const web3Modal = new Web3Modal(...
user avatar
1 vote
Accepted

How to Call Smart Contract Function After Migrations

try this: const D = artifacts.require("D"); const E = artifacts.require("E"); module.exports = async (deployer) => { await deployer.deploy(D) const d = await D.deployed();...
user avatar
0 votes

Listening to events using ethers.js on a hardhat test network

Check-out this example: async function main() { const EventEmitter = await ethers.getContractFactory("EventEmitter"); const eventEmitter = await EventEmitter.deploy(); await ...
user avatar
0 votes

[SOLVED]PatrickCollins Solidity Course 2022 - Lesson 7: 11:20:38 -> TypeError: ethers.getContract is not a function

[SOLVED] I tried to modify the line so it reads: await expect(fundMe.fund()).to.be.reverted Both tests seem to pass that way as you can see below So it is definitely the line but I still don't ...
user avatar
0 votes

Major differences between ethers-js and ethers-rs

I'm also pretty new in the smart contract sphere, but simplyfied: rust/C/C++ for the solana-ecosystem solidity with python/js frameworks for the ethereum ecosystem pls correct me if I'm mistaken here.
user avatar
0 votes

[SOLVED]PatrickCollins Solidity Course 2022 - Lesson 7: 11:20:38 -> TypeError: ethers.getContract is not a function

yarn add hardhat--dev @nomiclabs/hardhat-ethers@npm:hardhat-deploy-ethers ethers Ran this again and fixed the issue. Now test 1 passes but test returns the following error when it gets to await expect(...
user avatar
0 votes

window is not defined when used with next.js

Cong's answer there would work just fine but it doesn't give you a reason for the problem. Or alternate solutions... This question has also been asked many times outside of the ethereum fourm. The ...
user avatar
1 vote

How can I add an element to the array at an index of my choosing while altering the array size accordingly?

It looks like this has been answered here I do see that this answer only applies to calldata, however. Here is my "top of brain" naive / brute force approach. pseudo code: function ...
user avatar
0 votes

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray Ethers.js encrypt function error

Looks like we are missing await keyword. const jsonKey = new ethers.Wallet(process.env.PRIVATE_KEY); const encrypTkey = await jsonKey.encrypt(process.env.PASSWORD); It should work now.
user avatar
  • 21
0 votes

How to generate Private key, public key and address

Best way to generate 12/24 words of seed phrase or Ethereum private and public address key Use this tool - Seed phrases Generator
user avatar
  • 1
0 votes

window is not defined when used with next.js

You can change your implement web3 as bellow import Web3 from "web3"; let web3; if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') { // we are in the ...
user avatar
0 votes

require("fs-extra") not working even after adding/installing fs-extra (yarn add fs-extra)

yarn add fs-extra will add a package "fs-extra" to your package.json file but internally it's a top layer for FS. You just have to import fs and not fs-extra. Following will work. const fs = ...
user avatar
  • 21
0 votes

TypeError: transactionResponse.wait is not a function ethers.js

Calling a method on a contract returns a promise as does the wait method. In your example above you are not waiting for the promise to resolve. There are a couple of ways you can do this. One of them ...
user avatar
0 votes

Help Please Solidity version pragma statement in these files doesn't match the configured compilers in your config*contracts/hello-world.sol ("0.8.4")

try this: at hartdhat.config.js module.exports = { solidity: "0.7.1", }; 0.7.1--> 0.8.4 (solidity version you use in the smart contract) if not work, comment below, or git upload code ...
user avatar
0 votes

Help Please Solidity version pragma statement in these files doesn't match the configured compilers in your config*contracts/hello-world.sol ("0.8.4")

it needs to match up with what's in module.exports in your hardhat.config.js but the quotes in the contract are causing the problem try this pragma solidity ^0.8.4;
user avatar
  • 194
2 votes

TypeError: transactionResponse.wait is not a function ethers.js

Looks like control has jumped to line transactionResponse.wait(1) without waiting for a response from contract.store("4");. Use the await keywork and it will work. const transactionResponse =...
user avatar
  • 21
0 votes

Not able to use "connect()" method to sign transactions with different account in HARDHAT

I got the solution to this question from Hardhat Website. As we know that private keys are different for different Accounts, like I wanna use 2 or more Rinkeby Accounts in this case, so I need to ...
user avatar
0 votes

Error: /api/v0/object has been removed, use /api/v0/dag instead

Luckily it's started working. I have to use the script in my HTML header. <script src="https://unpkg.com/ipfs-api@9.0.0/dist/index.js" integrity="sha384-...
user avatar
1 vote

Is there a way to retrieve hexadecimal methodID from function ABI?

const iface = new ethers.utils.Interface(abi) const selector = iface.getSighash('transfer') You can also get the interface from the Contract object: const iface = contract.interface. If there is ...
user avatar
  • 1,089
1 vote

Is there a way to retrieve hexadecimal methodID from function ABI?

You can use the ethers.utils.id function. const { utils } = require('ethers') console.log(utils.id('transfer(address,uint256)').substring(0, 10)) https://docs.ethers.io/v5/api/utils/hashing/#utils-...
user avatar
0 votes

How to write the javascript test code on whether a smart contract function is successfully executed or not?

mercifully, you don't need the try catch blocks if you're expecting it to throw an error chai test syntax await expect(myContract.callFunc()).to.be.revertedWith("my expected error message") ...
user avatar
  • 194
1 vote
Accepted

console.log not working in scripts/deploy.js and in smart_contract in HardHat

After trying so hard I got the solution. Actually I've installed vs code extension Hardhat+Solidity provided by Hardhat officially. So, I uninstalled it and I installed Solidity extension by Juan ...
user avatar
0 votes

console.log not working in scripts/deploy.js and in smart_contract in HardHat

I can't remember if this solved the console.log issue for me, but I know for sure it was helpful for resolving import warnings on a 'missing file' I modified some solidity properties in .vscode/...
user avatar
2 votes

TypeError: Cannot read property 'length' of undefined - While deploying using hardhat

I got the answer from the MASTER himself, @PatrickAlphaC. When we call await getNamedAccounts in the above code, hardhat looks for the length of the named accounts in our hardhat.config.js We have to ...
user avatar
1 vote

How to get value from key in a map, where the key is an adress?

Try changing checkMap() to: function checkMap(address checkAdress) public returns (uint8) { return _addressMap[checkAdress]; } If you want to access the uint8 value stored at _addressMap[<...
user avatar
0 votes

Ethereum metamask payment on website not working

I am usually using ethersjs. But as far as I remember in the web3js you have to submit your transaction with .send() or .call() functions. I believe this will work: web3.eth.sendTransaction({ ...
user avatar
1 vote

Gnosis Transaction Failing On Polygon w/ "Transaction Underpriced" error

I was able to solve this with the following code: const executeTxResponse = await safeSdkInstance.executeTransaction(safeTransaction, { value: ethers.utils.parseEther('0'), gasPrice: ethers....
user avatar
  • 11
0 votes

error:Expected private key to be an Uint8Array with length 32

the default encoding in Buffer.from is try this: const privateKey = Buffer.from('b1292b419cb954157ba5a9f3385fc57a6ff31cdf80afe96d13af7335b5c55436', 'hex') as you can see I'm sending 'hex' to the ...
user avatar
2 votes
Accepted

Ethers.js signing a message to validate EOA is who they say they are

const message = 'Hello'; // In frontend const provider = new ethers.providers.Web3Provider(window.ethereum); await provider.send('eth_requestAccounts', []) // connects MetaMask const signer = ...
user avatar
  • 958
0 votes

TypeError: Cannot destructure property 'interface' of 'require(...)' as it is undefined

check the solidity version in the contract file and package-json file both versions should be the same, if not then download the specific version by the following command. npm install solc@...
user avatar

Top 50 recent answers are included