Issue on docs
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- javascript
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu tại /apps/builder-codes/builder-codes và tải https://docs.base.org/llms.txt để xác định cấu trúc tài liệu liên quan và các trang lân cận. Thêm hướng dẫn “Accept B20 payments” được cung cấp, bao gồm ví dụ JavaScript và các liên kết liên quan, sau đó xác minh rằng trang được hiển thị chính xác và các liên kết cùng mẫu mã của trang vẫn nguyên vẹn.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Path: /apps/builder-codes/builder-codes> ## Documentation Index
Fetch the complete documentation index at: https://docs.base.org/llms.txt
Use this file to discover all available pages before exploring further.
Accept B20 payments
Accept B20 token payments in your app and match each transaction to an order with onchain memos.
B20 is an ERC-20 superset. Standard 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 viem walletClient and publicClient:
import { parseUnits, stringToHex, hexToString, parseEventLogs } from 'viem';
const TOKEN = '0xB200...'; // the B20 token you accept
const MERCHANT = '0x...'; // where payments land
const ABI = [
{ type: 'function', name: 'decimals', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint8' }] },
{ type: 'function', name: 'transferWithMemo', stateMutability: 'nonpayable',
inputs: [{ name: 'to', type: 'address' }, { name: 'amount', type: 'uint256' }, { name: 'memo', type: 'bytes32' }],
outputs: [{ type: 'bool' }] },
{ type: 'event', name: 'Memo', inputs: [
{ name: 'caller', type: 'address', indexed: true },
{ name: 'memo', type: 'bytes32', indexed: true },
] },
];
// Read decimals because B20 tokens range from 6 to 18.
const decimals = await publicClient.readContract({ address: TOKEN, abi: ABI, functionName: 'decimals' });
// Pay 10 tokens, tagging the transfer with an order ID.
const hash = await walletClient.writeContract({
address: TOKEN, abi: ABI, functionName: 'transferWithMemo',
args: [MERCHANT, parseUnits('10', decimals), stringToHex('order-42', { size: 32 })],
});
// The Memo event carries the order ID back. Read it from the receipt.
const receipt = await publicClient.waitForTransactionReceipt({ hash });
const [memo] = parseEventLogs({ abi: ABI, logs: receipt.logs, eventName: 'Memo' });
console.log(hexToString(memo.args.memo, { size: 32 }).replace(/\0+$/, '')); // "order-42"
To collect with an allowance instead of a direct transfer, use 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.
Call 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.
- Ngôn ngữ chính
- JavaScript
- Star
- 337
- Fork
- 798
- Merge trung bình
- 13 giờ 7 phút
- Pull request đã merge (30 ngày)
- 57
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của base/docs
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
Issue tương tự
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Automattic/safe-publish#594 ·
-
内部文件键(绝对路径的 base64)泄漏到界面标签 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
dream-num/dsh-univer-office#104 ·
-
comp/dashboard invalid P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
NousResearch/hermes-agent#121143 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
avniproject/avni-webapp#1811 ·
-
area/auroraboot area/webui bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100