From d3a4f1f4e1847e6356158b98321558d968990458 Mon Sep 17 00:00:00 2001 From: Erhnysr Date: Wed, 8 Jul 2026 11:18:17 +0300 Subject: [PATCH] fix: correct code examples in Base Account SDK and payment READMEs - Fix provider.request() to use the single RequestArguments object signature ({ method, params }) instead of positional args - Add missing await on eth_requestAccounts so addresses is resolved before indexing addresses[0] - Fix payment README import path (@base/account-sdk -> @base-org/account) - Align examples with the real API: pay() throws on failure (no success:false/error branch); PaymentStatus uses reason, not error - Fix 'Base Accunt' typo -> 'Base Account' --- README.md | 13 ++++++++----- packages/account-sdk/README.md | 15 +++++++++------ .../account-sdk/src/interface/payment/README.md | 13 +++++-------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1dbf4b4b..d4715d35 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ yarn add @base-org/account 3. Request accounts to initialize a connection to wallet ```js - const addresses = provider.request({ + const addresses = await provider.request({ method: 'eth_requestAccounts', }); ``` @@ -181,10 +181,13 @@ yarn add @base-org/account 4. Make more requests ```js - provider.request('personal_sign', [ - `0x${Buffer.from('test message', 'utf8').toString('hex')}`, - addresses[0], - ]); + provider.request({ + method: 'personal_sign', + params: [ + `0x${Buffer.from('test message', 'utf8').toString('hex')}`, + addresses[0], + ], + }); ``` 5. Handle provider events diff --git a/packages/account-sdk/README.md b/packages/account-sdk/README.md index 1e7217df..93a90e17 100644 --- a/packages/account-sdk/README.md +++ b/packages/account-sdk/README.md @@ -78,7 +78,7 @@ 3. Request accounts to initialize a connection to wallet ```js - const addresses = provider.request({ + const addresses = await provider.request({ method: 'eth_requestAccounts', }); ``` @@ -86,10 +86,13 @@ 4. Make more requests ```js - provider.request('personal_sign', [ - `0x${Buffer.from('test message', 'utf8').toString('hex')}`, - addresses[0], - ]); + provider.request({ + method: 'personal_sign', + params: [ + `0x${Buffer.from('test message', 'utf8').toString('hex')}`, + addresses[0], + ], + }); ``` 5. Handle provider events @@ -127,7 +130,7 @@ ## Script Tag Usage -Base Accunt can be used directly in HTML pages via a script tag, without any build tools: +Base Account can be used directly in HTML pages via a script tag, without any build tools: ```html diff --git a/packages/account-sdk/src/interface/payment/README.md b/packages/account-sdk/src/interface/payment/README.md index 80f550f2..4dca5b3b 100644 --- a/packages/account-sdk/src/interface/payment/README.md +++ b/packages/account-sdk/src/interface/payment/README.md @@ -8,6 +8,7 @@ The payment interface provides a simple way to make USDC payments on Base networ import { pay } from '@base-org/account'; // Basic payment +// pay() resolves on success and throws on failure const payment = await pay({ amount: "10.50", to: "0xFe21034794A5a574B94fE4fDfD16e005F1C96e51", @@ -15,11 +16,7 @@ const payment = await pay({ testnet: true }); -if (payment.success) { - console.log(`Payment sent! Transaction ID: ${payment.id}`); -} else { - console.error(`Payment failed: ${payment.error}`); -} +console.log(`Payment sent! Transaction ID: ${payment.id}`); ``` ## Checking Payment Status @@ -27,7 +24,7 @@ if (payment.success) { You can check the status of a payment using the transaction ID returned from the pay function: ```typescript -import { getPaymentStatus } from '@base/account-sdk'; +import { getPaymentStatus } from '@base-org/account'; // Check payment status const status = await getPaymentStatus({ @@ -43,7 +40,7 @@ switch (status.status) { console.log(`Payment completed! Amount: ${status.amount} to ${status.recipient}`); break; case 'failed': - console.log(`Payment failed: ${status.error}`); + console.log(`Payment failed: ${status.reason}`); break; case 'not_found': console.log('Payment not found'); @@ -160,4 +157,4 @@ The payment result is always a successful payment (errors are thrown as exceptio - `sender?: string` - Sender address (present for pending, completed, and failed) - `amount?: string` - Amount sent (present for completed transactions, parsed from logs) - `recipient?: string` - Recipient address (present for completed transactions, parsed from logs) -- `error?: string` - Error message (present for failed status - includes both on-chain failure reasons and off-chain errors) \ No newline at end of file +- `reason?: string` - Reason for transaction failure (present for failed status - describes why the transaction failed on-chain) \ No newline at end of file