transfer, transferFrom, approve, balanceOf, and ERC-2612 permit all work, so an app that accepts ERC-20 tokens accepts B20 with no code changes.
B20’s new features include transfer policies, pausing, supply caps, and memos. This guide uses the memo: transferWithMemo works like transfer, but also attaches a bytes32 reference such as an order ID and emits a Memo event immediately after the standard Transfer event. Your app can read that Memo event to tie each payment to an order.
Tag a payment with a memo
This example reads the token’s decimals, sends a payment tagged with an order ID, then reads the memo back from the receipt. It uses your configured viemwalletClient and publicClient:
pay-with-memo.js
transferFromWithMemo. It emits the same Memo event.
Handle B20-specific reverts
A B20 transfer can revert where a standard ERC-20 would not. Surface these so a failed payment is visible, not silent:PolicyForbids: the sender or recipient is not authorized by the token’s transfer policy. Most tokens are open by default, but a regulated issuer can gate transfers with an allowlist or blocklist.- A paused transfer: the issuer paused the token’s
TRANSFERfeature.
publicClient.simulateContract with the same arguments before sending. It raises these as typed errors before the user signs, so you can show the reason instead of a failed transaction.
Related pages
- B20 token standard: the full interface, including memos, policies, pausing, and roles.
- Query B20 events: index
TransferandMemoevents with the CDP SQL API to reconcile payments against orders at scale. - Launch a B20 Token: create your own B20 token.