Questions tagged [hardhat]
The hardhat tag has no usage guidance.
54
questions
54
votes
6
answers
39k
views
Time-dependent tests with Hardhat?
For Ganache, there are several solutions.
What about Hardhat? They implemented their own local blockchain, Hardhat Network, which is different to Ganache.
42
votes
3
answers
21k
views
I see no way to obtain the return value of a non-view function (ethers.js)
In a Buidler/Hardhat test I have:
const { expect } = require("chai");
describe("SumOfTokens", function() {
it("Checks correct transfers", async function() {
const ...
4
votes
3
answers
4k
views
Hardhat deploy TypeError: ethers.getContract is not a function
I'd look for an alternative but not being able to use the ethers module is going to drive me nuts down the road. The code was copied from Patrick's Solidity Javascript course, the NFT section, Lesson ...
9
votes
3
answers
13k
views
ProviderError: max code size exceeded
I am trying to deploy an upgradeable smart contract on bsc testnet using hardhat. But after running npx hardhat run --network testnet scripts/deploy.js it gives me the following error.
ProviderError: ...
9
votes
3
answers
17k
views
An unexpected error occurred: Error: Cannot find module '@nomiclabs/hardhat-waffle' [Hardhat, openzeppelin]
I keep getting this error when doing: npx hardhat run scripts/sample-script.js --network testnet. Edited the name of my computer for security reasons. How do I put in the module 'nomiclabs/hardhat-...
7
votes
4
answers
20k
views
How can I connect a local Hardhat network to Metamask?
I have started a Hardhat network with default configuration using npx hardhat node. After running this command, I see Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/ and a list of ...
7
votes
3
answers
7k
views
Modify block number when testing with Hardhat
I see that is it is possible to define the timestamp of the next block (see here) in this way:
await network.provider.send("evm_setNextBlockTimestamp", [1625097600]);
await network.provider....
4
votes
1
answer
556
views
Hardhat chain fork on the test rather than config file
I saw that it is possible to test with Hardhat on a forked chain, via the config file.
Is it possible to do it on the test file instead? In a beforeEach, maybe.
I only want some of my tests to run on ...
4
votes
2
answers
4k
views
How to mock smart contract function for testing (in hardhat)
In my Test I want to mock an external function that I call inside my smart contract to test both conditions without writing and deploying an extra fake smart contract.
My Contract
//SPDX-License-...
4
votes
4
answers
7k
views
Followed hardhat test tutorial and got "TypeError: (0 , ethers_1.getAddress) is not a function" error
I follow the simple tutorial by hardhat here https://hardhat.org/hardhat-runner/docs/other-guides/waffle-testing by creating Greeter.sol and test/test.js. This leads to the following error:
1) ...
3
votes
2
answers
3k
views
How to get deployed contract address with ethers?
I using hardhat deploy (TypeScript) and am deploying two contracts: the first is a mock ERC20 token and a second is a crowdfunding contract that uses the mock when on a hardhat chain/localhost.
I am ...
2
votes
0
answers
173
views
Hardhat public network fork: Error calling view functions with ethers.js on browser
I have my hardhat network configured as a fork of Binance Smart Chain like this:
const config: HardhatUserConfig = {
solidity: {
version: "0.8.0",
settings: {
optimizer: {
...
2
votes
1
answer
3k
views
Stuck trying to verify a smart contract through hardhat
I am trying to verify on hardhat an nft-tutorial by chainlink but am unable to. I have converted most of the code to hardhat compatible. The contract address on Rinkeby is ...
0
votes
1
answer
442
views
'ethers' is not defined no-undef
I am making a very basic React app, and I'm following this tutorial. Ethers has been updated since, however. Here is my code for App.js:
import { useEffect } from 'react';
import { useState } from '...
0
votes
0
answers
578
views
Arithmetic Overflow Error
We're forking and updating sushiswap contracts. Right now, I'm trying to correct an overflow arithmetic error in the Masterchef Contract. We have tried using an uncheck{...} in the following function ...
24
votes
3
answers
23k
views
Listening to events using ethers.js on a hardhat test network
I am currently migrating a truffle project to hardhat. I am facing a problem with listening to events. I have a simple ERC20 token and want to listen to the Transfer event. I am running the contract ...
15
votes
3
answers
7k
views
Testing for custom error reverts in hardhat
I have a custom error described as such:
error AlreadyListed(address nftAddress, uint256 tokenId);
And in my tests, I'd like to check to see that it's thrown:
expect(await nftMarketplace.listItem(...
12
votes
3
answers
8k
views
Find address of a contract before deployment in Hardhat and Ethers.js
I have 2 contracts which take each other's addresses as constructor arguments. Here's the pseudocode,
constructor A(address B)
constructor B(address A)
I am deploying contracts using
const Contract = ...
11
votes
4
answers
6k
views
Received invalid block tag 87. Latest block number is 0
I ran a hardhat node just fine using npx hardhat node, but after I shut it down and restarted it, whenever I try to deploy something on the chain, I get the following error:
eth_getTransactionCount
...
8
votes
4
answers
10k
views
Warning: Contract code size exceeds 24576 bytes
I'm using hardhat and when trying to compile the code it shows me a warning containing
@uniswap/v2-periphery/contracts/UniswapV2Router02.sol:12:1: Warning: Contract code size exceeds 24576 bytes (a ...
6
votes
3
answers
3k
views
Property 'revertedWith' does not exist on type 'Assertion'
I'm running a test using waffle in hardhat.
import { assert, expect } from "chai"
.
.
.
it("can only be changed through governance", async () => {
await expect(box.store(...
6
votes
3
answers
12k
views
How to measure gas usage for each function call in Hardhat?
In Remix IDE, it's straightforward to deploy a smart contract and then execute a function call to see the debug log for gas usage. How may we see the gas consumption for function calls in hardhat? ...
5
votes
1
answer
5k
views
Cant validate authenticated message with ethers.js
I need to be able to retrive a document from the contract, have it signed by a users wallet and then send back to the contract and the signature validated.
Here's how I have address0 sign it on the ...
4
votes
1
answer
299
views
If `provider` is essential in communicating with the blockchain, how is this following code working?
Here is the smart contract code:
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface Bucket {
function drop(...
4
votes
2
answers
3k
views
Wait X block confirmations ethers contract deployment
Right now, I can deploy a contract with ethers and hardhat like so:
const SimpleStorageFactory = await ethers.getContractFactory("SimpleStorage")
const simpleStorage = await ...
3
votes
1
answer
8k
views
Invalid ENS name when running hardhat test
Am testing my smart contract using Hardhat, Waffle(beginner) and I can't understand why am getting Invalid ENS name error. 'Should only allow tokencreator to change token creator: AssertionError: ...
3
votes
2
answers
6k
views
How to get private key from hardhat ethers signer?
In hardhat I'd like to get the privateKey from a signer, the privateKeys are initialised in the hardhat.config networks.network.accounts.
import { ethers } from "hardhat";
import { Signer } ...
3
votes
2
answers
2k
views
How to find out the cost of deploying a contract in HardHat
I deploy the contract to the Rinkeby. Can I calculate the contract deployment cost from HardHat?
3
votes
2
answers
5k
views
Error: could not detect network
I am currently trying to deploy my DApp 'nftmarketplace' to the net using Vercel on the Goerli test network. However the app is failing to connect to the blockchain and I am getting the following ...
3
votes
4
answers
2k
views
TypeError: no matching function (argument="key", value="deployed", code=INVALID_ARGUMENT, version=6.5.1)
When trying to deploy my smart contract, I get this error message:
TypeError: no matching function (argument="key", value="deployed",
code=INVALID_ARGUMENT, version=6.5.1)
at main
...
3
votes
1
answer
3k
views
Cannot read properties of undefined (reading 'gteHardfork') when deploying contract using hardhat
I'm following this tutorial - https://www.freecodecamp.org/news/solidity-tutorial-hardhat-nfts/
but when running
npx hardhat test
or
npx hardhat run scripts/deploy.js
I'm getting the following ...
2
votes
1
answer
639
views
TDD Solidity: expect internal struct state
I'm a big fan of TDD/BDD so I figured hardhat and chai/waffle are a good start to learning smart contract development.
I've run into an issue though where I'm wondering what best practice would be to ...
2
votes
2
answers
3k
views
Ethers 6 transaction receipt events information
How i can get event name and params from tx receipt with Ethers 6?
I wanna write test to check if event was emitted.
Before each
beforeEach(async () => {
amount = tokens(10)
const ...
2
votes
1
answer
238
views
TypeError: Cannot read properties of undefined (reading 'checkUpkeep')
i'm getting this error while testing patrick collins smart-contract-lottery project, below is
the part where the error coming from.
describe("checkUpkeep", async function () {
...
2
votes
3
answers
2k
views
Hardhat: How to send multiple transactions to be mined in one block
How to send multiple transactions which will be mined in one block in Hardhat tests?
2
votes
3
answers
4k
views
how to hardhat test against a mainnet fork?
I'm using hardhat to fork the polygon mainnet by -
npx hardhat node --fork <ALCHEMY RPC ENDPOINT>
now i want to test on this local network. what is the command?
npx hardhat test is not working.
2
votes
1
answer
2k
views
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/utils' is not defined by "exports" in node_modules\ethers\package.json
Hello everyone I am trying to deploy my ERC721Upgradeable NFT Marketplace Smart Contracts in the local hardhat network but I am getting a error regarding it. I am using Openzeppelin's Upgradeable ...
1
vote
2
answers
694
views
How do I get the price chainlink price feed when testin with hardhat?
I have written a smart contract utilizing the chainlink price feed.
Now I want to test if the prices which I calculate in my smart contract are correct.
In solidity I fetch the current USD / ETH price ...
1
vote
3
answers
971
views
Hardhat test error, "TypeError: ABI not iterable" when running npx hardhat test
I am not sure where I am going wrong, but I think it is within my const [owner, _] = ...
area. I could be wrong, but I am not sure where, if anywhere I should be putting another argument, or ...
1
vote
1
answer
849
views
Using Multiple Initializers in Upgradable Smart Contract
For Upgradable Smart contract following pattern as specified here:
https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#avoid-initial-values-in-field-declarations
"Constructor&...
1
vote
1
answer
817
views
Prefunding wallets in HardHat
I know that Hardhat automatically prefunds each default wallet with ETHs, however I have a few questions with regards to that.
How does this prefunding work when I change the network (Say from ...
1
vote
1
answer
44
views
_burn() odd behaviour
I stumbled upon an issue with burn() in OpenZeppelin ERC20 contracts. I have the following test:
import { time, loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { ...
1
vote
2
answers
2k
views
Call A Smart Contract Function With Another Deployed Smart Contract Address As "msg.sender " From Hardhat Test
I have The Following Function in my Smart Contract
function functionName(uint256 param1, address param2)
external
override
{
require(msg.sender == marketContract, "...
1
vote
4
answers
316
views
Confused about the function of these lines of test code
Test file:
const {expect} = require("chai");
const {ethers} = require("hardhat");
describe("NFT Marketplace", function () {
let NFTMarket;
let nftMarket;
let ...
1
vote
1
answer
2k
views
How to test sending eth to function using ethers.js?
I'm net to eth dev and trying to test sending eth while assigning a value to betOnTeam function:
function betOnTeam(uint8 _team) public payable {
// assign usre to _team and add betting ...
1
vote
1
answer
359
views
How to write tests for "msg.sender" being a contract?
I want to write unit-test (using ethers.js on top of an hardhat-project) that covers a hook-function for OpenZeppelin's ERC1155 contract: onERC1155Received.
The special thing here is that the msg....
1
vote
2
answers
561
views
Best practices on testing an orchestrated contract
Let's define an orchestrated contract as one that contains at least one function that can be called by another contract - and that contract only.
The function would implement the restriction like this:...
0
votes
2
answers
633
views
Unable to verify contracts on polygon Amoy testnet
I have deployed some contracts on amoy testnet. To verify I followed this doc and I have also used the same approach for other chains as well. But in this case I am getting the following error:
Error ...
0
votes
1
answer
104
views
Trouble Shooting with Hardat, Solidity? Can you help?
I have been struggling to figure out this for a while and maybe someone can help? It is a bit lengthy to look through but if you have a good understanding of smart contracts and hardhat it may be easy ...
0
votes
3
answers
70
views
mappings return false but function returns true
I have a mapping uint256=>bool. I am giving projectId to see is it registered or not. I registered a project. I use chainlink automation for do something. But when i call checkuppkeep function for ...