ethers-viem
v2.47.9
Published
TypeScript Interface for Ethereum
Maintainers
Readme
Features
- Abstractions over the JSON-RPC API to make your life easier
- First-class APIs for interacting with Smart Contracts
- Language closely aligned to official Ethereum terminology
- Import your Browser Extension, WalletConnect or Private Key Wallet
- Browser native BigInt, instead of large BigNumber libraries
- Utilities for working with ABIs (encoding/decoding/inspection)
- TypeScript ready (infer types from ABIs and EIP-712 Typed Data)
- First-class support for Anvil, Hardhat & Ganache
- Test suite running against forked Ethereum network
... and a lot more.
Overview
// 1. Create the account
import { privateKeyToAccount } from 'ethers-viem/accounts';
const account = privateKeyToAccount(
'0xYOUR_PRIVATE_KEY'
);
// ✉️ Sign a simple message (EIP‑191)
const signature = await account.signMessage({
message: 'Hello world'
});
console.log(signature);
// 🧱 Sign raw bytes or hex
const sig = await account.signMessage({
message: { raw: '0x48656c6c6f' } // "Hello"
});
// 🧾 Sign EIP‑712 Typed Data
const signature = await account.signTypedData({
domain: {
name: 'MyApp',
version: '1',
chainId: 1n,
},
types: {
Mail: [
{ name: 'from', type: 'address' },
{ name: 'to', type: 'address' },
{ name: 'contents', type: 'string' },
],
},
primaryType: 'Mail',
message: {
from: '0x1234...',
to: '0xabcd...',
contents: 'Hello!',
},
});
// 🧩 Sign a raw 32‑byte hash
const sig = await account.sign({
hash: '0x0000000000000000000000000000000000000000000000000000000000000001'
});
Documentation
Head to the documentation to read and learn more about viem.
Community
Check out the following places for more viem-related content:
- Follow @wevm_dev, @_jxom, and @awkweb on Twitter for project updates
- Join the discussions on GitHub
- Share your project/organization that uses viem
Support
Sponsors
Contributing
If you're interested in contributing, please read the contributing docs before submitting a pull request.
Authors
License
MIT License
