hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.

OTHER License

Downloads
1.5M
Stars
7.2K
Committers
373

Bot releases are hidden (Show)

hardhat - Hardhat v2.4.3

Published by fvictorio over 3 years ago

This release fixes a Hardhat issue triggered by the latest versions of ethereumjs. If you have an error with a message like Cannot read property 'gteHardfork' of undefined or opts.tx.supports is not a function, please upgrade Hardhat to this version.

hardhat - hardhat-etherscan v2.1.4

Published by fvictorio over 3 years ago

This release adds support for verifying contracts in the Mumbai testnet.

hardhat - Hardhat v2.4.1

Published by fvictorio over 3 years ago

This release removes the warning shown by Hardhat when Solidity 0.8.x is used. Keep in mind that we currently support Solidity versions up to 0.8.4. Check the Solidity Support section of our docs to learn more.

hardhat - Hardhat v2.4.0

Published by fvictorio over 3 years ago

This release adds support for Solidity 0.8.x, as well as multiple new features for customizing the behavior of the Hardhat Network.

New error messages

Some error messages returned by Hardhat have changed. If you have tests that check the exact message of a Hardhat error, you may need to update them.

For example, before this release a require(false, "this is the reason") statement would've generated this error message:

Error: VM Exception while processing transaction: revert this is the reason

In this new version, the error message will be:

Error: VM Exception while processing transaction: reverted with reason string 'this is the reason'

You'll also get different error messages for panic errors (for example, if you are using solidity 0.8.0 and divide by zero) and for custom errors. See below to learn more about these new features.

New supported solidity features

Custom errors

Hardhat now recognizes custom errors. For example, given this contract:

contract Foo {
  error MyCustomError(uint code, string message);

  function test() public {
    revert MyCustomError(42, "failed for some reason");
  }
}

If you deploy Foo and call its test method, you'll now get a stack trace like this:

Error: VM Exception while processing transaction: reverted with custom error 'MyCustomError(42, "failed for some reason")'
    at Foo.test (contracts/Foo.sol:5)

Keep in mind that Hardhat can only recognize custom errors that are defined within your project. If you use mainnet forking and call some external contract that reverts with a custom error, Hardhat won't be able to parse it, and it will show an unrecognized error instead.

Panic codes

Solidity 0.8.0 introduced the concept of panic codes. In previous solidity versions, internal errors like dividing by zero were signaled by an invalid opcode being executed. The problem with this was that there wasn't a way to detect what kind of internal error was thrown and, worse, an error like this would consume all the remaining gas available in the transaction. Now, instead of using an invalid opcode, these errors use the revert opcode (the same used by the require function) and include a code that indicates what was the problem that caused the error.

For example, if you deploy this contract:

contract Foo {
  function test(uint x) public {
    uint y = 1 / x;
  }
}

and then you call the test function with value 0, Hardhat will now show a stack trace like this:

Error: VM Exception while processing transaction: reverted with panic code 0x12 (Division or modulo division by zero)
    at Foo.test (contracts/Foo.sol:3)

Top level functions

Hardhat now understands and generates correct stack traces when a top-level function is part of the call stack.

Customizing Hardhat Network's behavior

Arbitrary account modifications

Hardhat v2.4.0 includes several new RPC methods that let you modify anything about an address:

hardhat_setNonce

This method lets you change the nonce of an account. For example:

await network.provider.send("hardhat_setNonce", ["0x0d2026b3EE6eC71FC6746ADb6311F6d3Ba1C000B", "0x21"])

This will result in account 0x0d20...000B having a nonce of 33.

You can only use this method to increase the nonce of an account; you can't set a lower value than the account's current nonce.

hardhat_setBalance

This method lets you change the balance of an account. For example:

await network.provider.send("hardhat_setBalance", ["0x0d2026b3EE6eC71FC6746ADb6311F6d3Ba1C000B", "0x1000"])

This will result in account 0x0d20...000B having a balance of 4096 wei.

hardhat_setCode

This method lets you set the bytecode of an address. For example:

await network.provider.send("hardhat_setCode", ["0x0d2026b3EE6eC71FC6746ADb6311F6d3Ba1C000B", "0xa1a2a3..."])

This will result in account 0x0d20...000B becoming a smart contract with bytecode a1a2a3.... If that address was already a smart contract, then its code will be replaced by the specified one.

hardhat_setStorageAt

This method lets you modify any position in the storage of a smart contract. For example:

await network.provider.send("hardhat_setStorageAt", [
  "0x0d2026b3EE6eC71FC6746ADb6311F6d3Ba1C000B",
  "0x0",
  "0x0000000000000000000000000000000000000000000000000000000000000001"
])

This will set the first storage position inside that contract to 1.

The mapping between a smart contract's variables and its storage position is not straightforward except in some very simple cases. For example, if you deploy this contract:

contract Foo {
  uint public x;
}

And you set the first storage position to 1 (as shown in the previous snippet), then calling foo.x() will return 1.

Minimum gas price

You can now configure Hardhat Network so that it only mines transactions that have a gas price equal to or above a given threshold. If automining is enabled, transactions with a lower gas price will be rejected. If automining is disabled, this transactions will be kept in the mempool but they won't be mined.

To configure the minimum gas price, set the minGasPrice property in the Hardhat Network configuration:

module.exports = {
  networks: {
    hardhat: {
      minGasPrice: 1_000_000_000
    }
  }
}

You can also change this value in runtime using the new hardhat_setMinGasPrice RPC method:

await network.provider.send("hardhat_setMinGasPrice", ["0x77359400"])

Transaction replacement

Hardhat now supports transaction replacement when automining is disabled. This means that if you send a transaction from the same address and with the same nonce as another transaction already present in the mempool, but with a higher gas price, this transaction will be replaced. The new gas price needs to be at least 10% higher than the gas price of the current transaction.

Dropping transactions

There is a new hardhat_dropTransaction RPC method that can be used to remove transactions from the mempool:

const txHash = "0xabc..."
const result = await network.provider.send("hardhat_dropTransaction", [txHash])

There are three possible scenarios when this method is used:

  • txHash corresponds to a transaction in the mempool. In this case, the transaction will be removed and result will be true.
  • txHash doesn't correspond to a transaction. In this case nothing will happen and result will be false.
  • txHash corresponds to a mined transaction. In this case an InvalidArgumentsError will be thrown.

Other changes

  • Hardhat now supports the HTTP_PROXY and HTTPS_PROXY environment variables. This is only used to download the Solidity compilers, not for JSON-RPC networks or mainnet forking. Thanks @cdesch for working on this! (PR #1291, issue #1280)

  • When the balance of an account was set to a hexadecimal value, Hardhat would throw a very opaque error. Now a better error message is shown. Thanks to @Bidon15 for this contribution! (PR #1458, issue #1427)

  • Forking from xDai will cache data to disk if you ping a block older with 38 confirmations or more. Thanks to @jacobrosenthal for this! (PR #1557)

hardhat - hardhat-etherscan v2.1.3

Published by fvictorio over 3 years ago

This release adds support for verifying contracts deployed on the Optimism networks (Optimistic Ethereum, Optimistic Kovan) and in the Matic (Polygon) POS Network.

Thanks to @ayushm2003 and @BrknRobot for their contributions! 👷‍♂️

hardhat - Hardhat v2.3.3

Published by fvictorio over 3 years ago

This release fixes an issue introduced by recent versions of ethereumjs. If you see an error like TypeError: Cannot read property 'param' of undefined or TransactionExecutionError: Assertion failed, please upgrade to this version and try again. See #1537 to learn more.

hardhat - Hardhat v2.3.0

Published by fvictorio over 3 years ago

This release adds support for the debug_traceTransaction RPC method, along with some other minor changes.

debug_traceTransaction

The debug_traceTransaction method receives the hash of a transaction and returns a low-level structure that describes how the EVM executed that transaction. This is mainly useful for higher-level tools, and it's a major step towards letting Brownie integrate with Hardhat.

debug_traceTransaction can be used both in local and fork modes. This means that you can use it with any transaction in mainnet, even if the node you are using doesn't support this method. If you use an archive node, you can trace any historical transaction after the Spurious Dragon fork (2016).

You can read more about this method here, but notice that Hardhat doesn't support the tracer and timeout options.

Return hash of a failed transaction

When a sent transaction fails, the JSON-RPC node will include its hash in the response. This is another component needed to better integrate Brownie with Hardhat, but it's also useful for any tool that wants to leverage it. The JSON response of a failed transaction now looks like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32603,
    "message": "Error: VM Exception while processing transaction: revert failed",
    "data": {
      "txHash": "0x03a5b783cfd268687f95b741c92ae7e2e7dc611535d6b4f2a8d291df410c33cc"
    }
  }
}

Other changes

This release also includes two minor improvements (thanks to @Bidon15 for these contributions!):

  • When you run Hardhat with the --verbose flag, the output will include the path to the hardhat config file that was loaded. This is useful when you are trying to initialize a project, but Hardhat detects a config file in an upper directory. Issue: #1443, PR: #1454.
  • There was a bug in the error message shown when a library was missing. Issue: #1401, PR: #1405.
hardhat - hardhat-etherscan v2.1.2

Published by fvictorio over 3 years ago

This release adds support for the HECO and fantom networks to the etherscan plugin.

hardhat - Hardhat v2.2.1

Published by fvictorio over 3 years ago

This release fixes a bug where a contract's code was not being properly removed after a selfdestruct (#1415).

hardhat - Hardhat v2.2.0: Berlin support

Published by alcuadrado over 3 years ago

Hardhat v2.2.0, which includes support for the new Berlin hard fork, has been released.

This version also includes some small fixes, most notably, it fixed some problems when downloading solc on MacOS.

Known issues

To workaround a recently discovered bug in @ethereumjs/vm, this release saves the EVM state in a non-standard way which can't produce valid state roots.

What this means in practice is that the state root in block headers is not valid. If your tests don't depend on it, they should work correctly.

Note that this same limitation is always present when forking from another network, so if you are using this feature, you can ignore this section.

As soon as this issue is fixed upstream, we'll publish a new version which will compute valid state roots again.

Default config changes

This version changes Hardhat Network's default config to match Mainnet's behavior:

  • The default hardfork is now "berlin".
  • The default blockGasLimit is now 12450000 (a reasonable value for Mainnet blocks at the time of the release).
  • The default gas matches the block gas limit value.

Complete list of changes

  • Add support for the Berlin hardfork (#1376 #1383 #1381 #1379)
  • Update Hardhat Network's default config to match Mainnet (#1387)
  • Make Hardhat Network's default gas match the block gas limit (#1390)
  • Fix the Solidity compiler downloader, which was failing on MacOS (#1392)
  • Fix our implementation of EIP-1898 so it matches Geth's (#1366)
  • Fix a bug in eth_estimateGas that was triggered when running it with an old block (#1366)
  • Make the params of eth_sendTransaction, eth_estimateGas, and eth_call match those of Geth. eth_estimateGas now ignores the nonce field. (#1366)
  • Upgrade to @ethereumjs/vm v5 (#1337 #1370 #1394)
  • Workaround an issue in @etheruemjs/vm's DefaultStateManager (#1406)
hardhat - Hardhat v2.1.2

Published by fvictorio over 3 years ago

This release makes it easier to use a custom VM with hardhat. Most users shouldn't be affected by this change.

This release also fixes an issue with mainnet forking when using ArchiveNode.io as the remote node.

hardhat - hardhat-ethers v2.0.2

Published by fvictorio over 3 years ago

This release adds a new getSigner method that can be used with an address to get a signer object for that address:

const signer = await ethers.getSigner("0xabc...");

Of course, this signer can be used for writing only if that address is unlocked. Otherwise it can be used in a read-only fashion.

This release also fixes getContractAt so that, if there are no signers available, you still get a contract instance that can only be used for read operations.

Finally, it's now possible for a typescript plugin to declare which methods are added to the ethers object.

hardhat - Hardhat v2.1.1

Published by fvictorio over 3 years ago

This release fixes a bug introduced in 2.1.0 that was causing the gas estimation to be executed in the context of the latest block and not in the pending ("next") block.

hardhat - Hardhat v2.1.0

Published by fvictorio over 3 years ago

This release adds mempool support to Hardhat, with two possible mechanisms for mining transactions: automining (the current behavior) and interval mining. You can also disable both mechanisms and mine new blocks programmatically. Check the docs to learn more.

Besides that:

  • Starting now, Hardhat will warn you if you are using an unsupported version of solc. This doesn't mean that you can't use those versions, only that some Hardhat features, like stack traces, might not work correctly.
  • Ropsten forking now has cache support, if you fork from a block that is at least 100 blocks old.
  • A bug around the eth_getStorageAt was fixed (thanks @fubhy!)
hardhat - Hardhat v2.0.11

Published by fvictorio over 3 years ago

This release fixes two bugs in the Hardhat Network.

The first one was related to how internal errors were handled during a fork. If you were seeing revert errors in some runs but not in others, this version should fix that.

The second bug was a race condition that caused the fork to sometimes throw an error about an nonexistent directory when it was started.

hardhat - hardhat-vyper v2.0.1

Published by fvictorio over 3 years ago

This release adds support for mixing Solidity and Vyper files in the same project.

Thanks a lot to @transferAndCall for working on this!

hardhat - Hardhat v2.0.10

Published by fvictorio over 3 years ago

This PR fixes a problem introduced in v2.0.9 that caused Hardhat to stop working with node 14.

Besides that, there are two important fixes to mainnet forking:

  • The nonces of the unlocked accounts now use the values in the forked chain, instead of being set to 0. This was causing an issue when several contracts were deployed with the first default account.
  • The timestamps of new blocks are now computed based on the forked block. This means that if, for example, the forked block has a timestamp of 2021-01-01 06:00, and you mine a block one minute after forking, the timestamp of that block will be 2021-01-01 06:01 instead of using the current date. There's a slight change that this fix breaks something for you, so keep this change in mind

Huge thanks to @fubhy for contributing to this release!

hardhat - Hardhat v2.0.9

Published by fvictorio over 3 years ago

This release adds support for forking the Kovan and xDAI networks. Plus:

  • The eth_signTypedData_v4 RPC method is now supported and the eth_signTypedData was removed since its EIP is not finished.
  • An edge case with console.log was fixed (see #1182)
hardhat - hardhat-etherscan v2.1.1

Published by fvictorio over 3 years ago

This release includes some improvements to the hardhat-etherscan plugin.

Ambiguous contracts

The plugin tries to automatically detect the contract that is being verified, but sometimes you can have two different contracts that generate the same bytecode. In previous versions this meant that you couldn't verify those contracts without modifying one of them. Now you can use the --contract parameter to specify which of the ambiguous contracts should be used.

Undetectable libraries

The plugin also tries to detect which libraries are linked to the contract that is being verified, but there are some edge cases where this is not possible (for example, if a library is only used in the constructor). Now you can use the --libraries parameter to pass these undetectable libraries. Learn more here.

Binance Smart Chain

We added support for BSC and its testnet. Huge thanks to @purperen and @guagualvcha who contributed to this.

hardhat - Hardhat v2.0.8 released

Published by alcuadrado almost 4 years ago

This is release includes the following improvements and bug fixes: