Skip to content

Add abigen state-changing writes via Wallet (extends #68)#98

Merged
koko1123 merged 1 commit into
mainfrom
feat/abigen-writes
Jun 11, 2026
Merged

Add abigen state-changing writes via Wallet (extends #68)#98
koko1123 merged 1 commit into
mainfrom
feat/abigen-writes

Conversation

@koko1123

@koko1123 koko1123 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Completes the comptime contract-bindings flagship with state-changing writes, so the abigen surface now covers reads + events + writes.

const weth = Weth.at(weth_address);
const tx_hash = try weth.send(&wallet, "transfer", .{ recipient, amount });
  • send(self, wallet, comptime name, args) ![32]u8 -- builds the same selector ++ encode(args) calldata as call (shared encodeCall helper) and submits via Wallet.sendTransaction, returning the tx hash.
  • sendValue(..., value: u256) for payable functions.
  • sendAndWait(..., max_attempts) !TransactionReceipt waits for the receipt.
  • Naming a view/pure function in send is a @compileError directing the caller to call (you don't broadcast a read).

Verification

832/832 tests on 0.16.0, fmt clean, docs build, plus a new Anvil integration test that does a real send("transfer", ...) and checks the receipt.

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added methods for state-changing contract calls: send, sendValue, and sendAndWait
    • Support for payable ETH-attaching calls
    • sendAndWait enables transaction receipt polling
  • Documentation

    • Added guide for writing to contracts with examples and error handling

Completes the comptime contract-bindings surface with writes:
- send(self, wallet, comptime name, args) ![32]u8 -- builds the same
  selector ++ encode(args) calldata as call() (shared encodeCall
  helper) and submits via Wallet.sendTransaction, returning the tx hash
- sendValue(..., value: u256) for payable functions
- sendAndWait(..., max_attempts) !TransactionReceipt
- naming a view/pure function in send is a @CompileError directing the
  caller to call() instead

832/832 tests pass on 0.16.0; new integration test exercises a real
send against Anvil; docs updated with a write example.
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eth-zig Ready Ready Preview, Comment Jun 11, 2026 4:39pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extends eth.zig's abigen module to support state-changing contract calls via *Wallet. It introduces send, sendValue, and sendAndWait methods that encode typed arguments into calldata and submit them through the wallet layer, plus compile-time enforcement blocking view/pure functions and shared calldata encoding reused by both read and write paths.

Changes

Abigen write API with wallet integration

Layer / File(s) Summary
API documentation and specification
src/abigen.zig (lines 31–37, 56–57, 150–155), docs/content/docs/abigen.mdx (lines 73–110), CHANGELOG.md (line 11)
Module and public API documentation updated to specify send, sendValue, and sendAndWait for state-changing calls with shared calldata logic, compile-time blocking on view/pure functions, and full read+write+event surface completion. User-facing documentation and changelog entry added.
Shared calldata encoding
src/abigen.zig (lines 78, 216–229, 231–250)
Wallet module imported; call refactored to use internal encodeCall helper; new encodeCall(allocator, name, args) helper introduced to build selector ++ ABI-encode(args) for reuse by both read and write operations.
Write operations and writability enforcement
src/abigen.zig (lines 260–291, 292–311, 390–403)
assertWritable comptime helper added to reject view/pure functions at compile time; send implemented to delegate to sendValue with value = 0; sendValue and sendAndWait implemented to assert writability, build calldata, and submit via wallet.sendTransaction or wallet.sendTransactionAndWait, returning transaction hash or receipt respectively.
Write API validation and integration tests
src/abigen.zig (lines 1290–1385), tests/integration_tests.zig (lines 297–357)
Unit tests validate encodeCall output, verify send/sendValue/sendAndWait signatures and return types, and confirm end-to-end typechecking. Integration test deploys a STOP stub contract, binds it as ERC-20, executes transfer via send and sendAndWait, and asserts receipt success and address fields.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • StrobeLabs/eth.zig#97: Introduces the wallet module and sendTransaction/sendTransactionAndWait implementations that the new abigen write API builds upon and wires into.

Poem

🐰 Hops through the blockchain bright,
Reads and writes, day and night,
State-changing calls now flow,
Through typed wallets that glow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add abigen state-changing writes via Wallet (extends #68)' clearly and specifically summarizes the main change: adding state-changing write support to the abigen contract bindings via a Wallet interface.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/abigen-writes

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/content/docs/abigen.mdx (1)

130-133: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Stale limitation text contradicts the new write functionality.

The "Scope and limitations" section still states "Writes are deferred. State-changing calls (which would take a *Wallet) are a planned follow-up." This is now incorrect, as this PR implements the write surface (send, sendValue, sendAndWait).

Update this section to reflect that writes are now supported. For example:

  • Remove the "Writes are deferred" bullet entirely, or
  • Replace it with a note about what write features are complete (e.g., "State-changing calls via send, sendValue, and sendAndWait are supported; see Writing to a contract").
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/content/docs/abigen.mdx` around lines 130 - 133, Update the "Scope and
limitations" text to remove the stale claim that "Writes are deferred" and
instead state that state-changing calls are supported; specifically edit the
section to either delete the bullet or replace it with a short note such as:
"State-changing calls via send, sendValue, and sendAndWait are supported; see
Writing to a contract." Ensure the updated copy references the implemented
methods send, sendValue, and sendAndWait to guide readers to the new write
surface.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/content/docs/abigen.mdx`:
- Around line 130-133: Update the "Scope and limitations" text to remove the
stale claim that "Writes are deferred" and instead state that state-changing
calls are supported; specifically edit the section to either delete the bullet
or replace it with a short note such as: "State-changing calls via send,
sendValue, and sendAndWait are supported; see Writing to a contract." Ensure the
updated copy references the implemented methods send, sendValue, and sendAndWait
to guide readers to the new write surface.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c263648f-20a9-462d-870f-d6bfc556a30a

📥 Commits

Reviewing files that changed from the base of the PR and between b735c86 and 395d573.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • docs/content/docs/abigen.mdx
  • src/abigen.zig
  • tests/integration_tests.zig

@koko1123
koko1123 merged commit f0a61d8 into main Jun 11, 2026
12 checks passed
@koko1123
koko1123 deleted the feat/abigen-writes branch June 11, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant