Skip to content

Commit

Permalink
docs(README): add real-life helper
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax authored Oct 25, 2024
1 parent dd99c8e commit 57d7ff0
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { foundry } from 'viem/chains';
import { traceActions, traced } from 'viem-tracer';

const client = createTestClient({
mode: 'anvil',
mode: "anvil",
chain: foundry,
transport: traced( // Automatically trace failed transactions (or programmatically)
http(),
Expand All @@ -40,13 +40,19 @@ const client = createTestClient({

// Returns the call trace as formatted by the requested tracer.
await client.traceCall({
account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
value: parseEther('1'),
account: "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
to: "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
value: parseEther("1"),
// tracer: "prestateTracer", // Defaults to "callTracer".
});

// Failing `eth_estimateGas` and `eth_sendTransaction` RPC requests will automatically append the transaction traces to the error:
await client.writeContract({
abi: erc20Abi,
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
functionName: "transfer",
args: ["0xA0Cf798816D4b9b9866b5330EEa46a18382f251e", 100_000000n],
});

// 0 ↳ FROM 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
// 0 ↳ CALL (0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48).transfer(0xf39F...0xf3, 100000000) -> ERC20: transfer amount exceeds balance
Expand Down

0 comments on commit 57d7ff0

Please sign in to comment.