Buidler comes built in with Buidler EVM, a local Ethereum network designed for development. It allows you to deploy your contracts, run your tests and debug your code.
How does it work?
- It mines a block with each transaction that it receives, in order and with no delay.
- It's backed by the
ethereumjs-vmEVM implementation, the same one used by ganache, Remix and Ethereum Studio.
- It supports the following hardforks:
How can I use it?
- Buidler will always spin up an instance on startup when
defaultNetworkis empty or set to
buidlerevm. It's the default behavior.
- It can be used to run tests, in the console, scripts and tasks
- Plugins (web3.js, ethers.js, Truffle, etc) connect directly to the provider
- There's no need to make any changes to your tests or scripts.
- It's simply another network and it can be used with
Solidity stack traces
Buidler EVM has first-class Solidity support. It always knows which smart contracts are being run, what they do exactly and why they fail.
This is an example of a Buidler EVM exception:
Error: Transaction reverted: function selector was not recognized and there's no fallback function at ERC721Mock.<unrecognized-selector> (contracts/mocks/ERC721Mock.sol:9) at ERC721Mock._checkOnERC721Received (contracts/token/ERC721/ERC721.sol:334) at ERC721Mock._safeTransferFrom (contracts/token/ERC721/ERC721.sol:196) at ERC721Mock.safeTransferFrom (contracts/token/ERC721/ERC721.sol:179) at ERC721Mock.safeTransferFrom (contracts/token/ERC721/ERC721.sol:162) at TruffleContract.safeTransferFrom (node_modules/@nomiclabs/truffle-contract/lib/execute.js:157:24) at Context.<anonymous> (test/token/ERC721/ERC721.behavior.js:321:26)
Automatic error messages
Buidler EVM always knows why your transaction or call failed, and uses this information to make debugging your contracts easier.
When a transaction fails without a reason, Buidler EVM will create a clear error message in the following cases:
Calling a non-payable function with ETH
Sending ETH to a contract without a payable fallback function
Calling a non-existent function when there's no fallback function
Calling a function with incorrect parameters
Calling an external function that doesn't return the right amount of data
Calling an external function on a non-contract account
Failing to execute an external call because of its parameters (e.g. trying to send too much ETH)
Calling a library without
Incorrectly calling a precompiled contract
Buidler EVM allows you to print logging messages and contract variables calling
console.log() from your Solidity code. You can see an example in the Sample Project. Follow the steps in Quick Start to try it out.
- You can use it in calls and transactions. It works with
viewfunctions, but not in
- It always works, regardless of the call or transaction failing or being successful.
- To use it you need to import
- It works with Solidity 0.5.x and 0.6.x.
- You can call
console.logwith up to 4 parameters in any order of following types:
- There's also the single parameter API for the types above, and additionally
bytes1.. up to
console.logString(string memory s)
console.logBytes(bytes memory b)
console.logimplements the same formatting options that can be found in Node.js'
console.log, which in turn uses
console.log("Changing owner from %s to %s", currentOwner, newOwner)
- It works with any library: web3.js, ethers.js, truffle-contract, waffle, etc.
console.logis implemented in standard Solidity and then detected in Buidler EVM. This makes its compilation work with any other tools (like Remix or Truffle).
console.logcalls can run in other networks, like mainnet, kovan, ropsten, etc. They do nothing in those networks, but spend a minimal amount of gas.
Buidler EVM initial state
Buidler EVM is initialized by default in this state:
- A brand new blockchain, just with the genesis block.
- 20 accounts with 10.000 ETH each
To customise it, take a look at the configuration section.
JSON-RPC methods support
eth_getFilterChanges – Only for block filters
Special testing/debugging methods
evm_increaseTime– same as Ganache.
evm_mine– same as Ganache, except it doesn’t accept a timestamp.
evm_revert– same as Ganache.
evm_snapshot– same as Ganache.
Supported Solidity versions
Buidler EVM can run any smart contract, but it only understands Solidity 0.5.1 and newer.
If you are compiling with an older version of Solidity, or using another language, you can use Buidler EVM, but Solidity stack traces won't be generated.
Solidity optimizer support
Buidler EVM can work with smart contracts compiled with optimizations, but this may lead to your stack traces' line numbers being a little off.
We recommend compiling without optimizations when testing and debugging your contracts.