Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🎩🪄 Easily deal any amount of any ERC20 tokens to any account on the hardhat network

License

NotificationsYou must be signed in to change notification settings

Rubilmax/hardhat-deal

Repository files navigation

npm packageBuild StatusDownloadsIssuesCommitizen FriendlySemantic Release

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.

Installation

npm install hardhat-deal
yarn add hardhat-deal

Import the plugin in yourhardhat.config.js:

require("hardhat-deal");

Or if you are using TypeScript, in yourhardhat.config.ts:

import"hardhat-deal";

Usage

Testing

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);

Standalone task

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.

Configuration

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},};

About

🎩🪄 Easily deal any amount of any ERC20 tokens to any account on the hardhat network

Topics

Resources

License

Stars

Watchers

Forks

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp