viem-deal is a utility library, currently at stable version 2.0.4 (released October 2024), designed to extend viem clients with powerful capabilities for manipulating ERC20 token balances on development and test networks. It enables developers to "deal" arbitrary amounts of any ERC20 token to any account on `setStorageAt`-compatible environments like Anvil, Hardhat, or Tevm-based forks. This functionality mirrors Foundry's `deal` cheat code, achieving balance manipulation by dynamically identifying the correct storage slot for an account's balance using `eth_createAccessList` and then overriding that storage slot's value with `setStorageAt`. The library provides a rapid and efficient method for setting up test scenarios with precise token balances without actual on-chain minting or transfers. The project shows a frequent release cadence, with multiple patch and minor releases in October 2024. A key differentiator is its reliance on RPC cheat codes, which streamlines test setup compared to transactional interactions. The package ships with TypeScript types, ensuring a type-safe development experience.
npm install viem-dealVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a viem test client, extend it with `dealActions`, and then use the `deal` function to transfer 100 USDC to a specified test address on an Anvil-based local blockchain. It showcases the primary usage pattern for modifying ERC20 balances in a test environment.
Update calls to the `deal` function to use `account` instead of `recipient`. For example, change `recipient: '0x...'` to `account: '0x...'`. If no account is provided, ensure the client is configured with a default account.
Avoid using `viem-deal` for very small amounts or 'dust' of stETH. If stETH balance manipulation is necessary, consider using larger, more substantial amounts or explore alternative methods specific to stETH's underlying mechanics.
For projects using modern Node.js and TypeScript, ensure your `tsconfig.json` and `package.json` are configured for ESM (e.g., `"type": "module"`, `"module": "nodenext"` or `"bundler"` in `tsconfig.json`). If encountering `ERR_MODULE_NOT_FOUND`, verify import paths and consider updating to the latest patch version which might have stabilized module exports.
Ensure your viem client is extended with `dealActions`: `const client = createTestClient(...).extend(dealActions);`
Rename the `recipient` parameter to `account` in your `deal` function calls: `await client.deal({ erc20: '0x...', account: '0x...', amount: parseUnits('100', 6) });`First, ensure `viem-deal` is installed (`npm install viem-deal`). Verify that your `import` statements are correct (e.g., `import { dealActions } from 'viem-deal';`). If using TypeScript or a bundler, confirm that your `tsconfig.json` (`"module"`, `"moduleResolution"`, `"type"`) and `package.json` (`"type"`) are configured correctly for ESM. Consider clearing `node_modules` and reinstalling.