Anchor a Walrus blob ID per EVM address, in 50 lines of Solidity.
Write a Solidity contract that stores one Walrus blob ID per caller, then verify it with a Foundry test suite. The
contract is small enough to fit on one screen; the goal is to nail the three load-bearing choices — bytes32
storage, msg.sender-keyed mapping, and a plain read path that hands off URL construction to the
off-chain client.
What you'll write
Three sections, all editing one file: src/WalrusAnchor.sol. Each section's key moment is the
one decision that makes the rest of the section fall into place.
-
s01 · anchor state
Anchor state — the on-chain footprint
Picking
bytes32for the blob ID. Walrus blob IDs are exactly 32 bytes (a BLAKE2b-256 hash of the content), so they slot into a single storage word — one SSTORE per anchor regardless of underlying blob size. Usingstringorbyteswould double the cost and break the constant-gas property. -
s02 · write path
The write path —
anchor(bytes32 blobId)Using
msg.senderas the mapping key (rather than taking anaddress ownerparameter). This makes the on-chain authentication implicit — the EVM has already proven who the caller is by the time we reach this line, so we don't need any explicitrequire(msg.sender == owner)check. -
s03 · read path
The read path —
blobOf(address)and the equivalence gateThe read path is a plain mapping lookup with no decoding, no aggregation, and no events — the off-chain client uses the returned
bytes32to build a URL likehttps://aggregator.walrus-testnet.walrus.space/v1/blobs/<blobId-as-base64url>and fetches the actual content from there. The contract's job ends at returning the pointer.
Verification
The reference-app's Foundry suite is the equivalence gate. Run it inside the workspace:
forge test
All 4 tests should pass: storesBlobIdForCaller · emitsEvent · overwritesPrevious · blobOf returns zero for unknown.
Sources
Read the reference-app on GitHub, or jump to the parent showcase for the full design context.
- Reference-app: lessons/01-walrus-solidity-basics/reference-app/ — a Foundry project with
WalrusAnchor.sol+ tests, forge-std-free so it runs offline. - Lesson sections: lessons/01-walrus-solidity-basics/sections/ — the three section prompts the conductor walks you through.
- Parent showcase: mystenlabs/evm-sui — Walrus integrations — the index for all six EVM × Walrus reference apps.