





This plugin allows the developer to deal arbitrary amount of ERC20 tokens to any account on the hardhat network, to ease test development. The storage value of the mappingbalanceOf is manipulated in order to manipulate the balance of the given user.
The plugin is shipped with a list of storage slots, which enable faster deals. Additionnally, the developer can provide a mapping of storage slots on custom ERC20s or edit the hardhat configuration on-the-fly (for example when deploying custom ERC20s during tests). If the ERC20 is not found in the configuration, the plugin automatically tries to brute-force the storage slot of the mappingbalanceOf, and throws an error if it cannot.
Import the plugin in yourhardhat.config.js:
Or if you are using TypeScript, in yourhardhat.config.ts:
import{deal}from"hardhat-deal";constlusd="0x5f98805A4E8be255a32880FDeC7F6728C6568bA0";constuser="0x7Ef4174aFdF4514F556439fa2822212278151Db6";constamount="10000000000000000000";// 10 LUSD// Deal 10 LUSD to the userawaitdeal(lusd,user,amount);// Optionnally provide a last parameter specifying how far to brute-force the storage slot (default: 12)awaitdeal(lusd,user,amount,15);This plugin also provides a taskdeal that can be called with hardhat to deal ERC20 tokens on a separate hardhat node:
npx hardhat deal<recipient><ERC20 symbol or address><amount> --network localhost
For example:
npx hardhat deal<recipient> WETH 2000000000000000000 --network localhost
Runnpx hardhat deal --help to see the list of supported ERC20 symbols.
This plugin extendsHardhatUserConfig object with an optionaldealSlots field, allowing one to customize the default storage slots used to deal ERC20 tokens, for faster usage (because the plugin no longer needs to brute-force the ERC20 storage slot).
This is an example of how to set it:
module.exports={networks:{// If using an external network, you can optionnally provide a custom rpc endpoint to manipulate the network's storage.tenderly:{rpcEndpoints:{setStorageAt:"tenderly_setStorageAt",},},},dealSlots:{"0x5f98805A4E8be255a32880FDeC7F6728C6568bA0":2,// LUSD},};