The Base Account SDK provides two distinct sets of functionality:
Purely functional payment and subscription APIs that work immediately without any SDK setup or wallet connection.
Complete SDK for connecting to Base Account wallets and interacting with the Ethereum blockchain.
Base Pay allows you to accept USDC payments with just 3 lines of code. No SDK instantiation or wallet connection required.
# npm
npm install @base-org/account
# yarn
yarn add @base-org/account
import { pay } from '@base-org/account';
// That's it! Just call the pay function directly
const payment = await pay({
amount: "10.50", // Amount in USDC
to: "0xYourWalletAddress", // Your wallet address
testnet: true // Use testnet for testing
});
console.log(`Payment successful! ID: ${payment.id}`);
import { getPaymentStatus } from '@base-org/account';
const status = await getPaymentStatus({
id: payment.id,
testnet: true
});
console.log(`Payment status: ${status.status}`);
Base Subscriptions lets you create recurring USDC payments
import { subscribe } from '@base-org/account';
// Create a monthly subscription - that's all!
const subscription = await subscribe({
recurringCharge: "9.99", // Amount to charge per period
subscriptionOwner: "0xYourAppAddress", // Your app's address
periodInDays: 30, // Billing period
testnet: true // Use testnet for testing
});
console.log(`Subscription created! ID: ${subscription.id}`);
import { getSubscriptionStatus } from '@base-org/account';
const status = await getSubscriptionStatus({
id: subscription.id,
testnet: true
});
console.log(`Active: ${status.isSubscribed}`);
console.log(`Next charge: ${status.nextPeriodStart}`);
import { base } from '@base-org/account';
// Prepare the charge (get the transaction data)
const chargeCalls = await base.subscription.prepareCharge({
id: subscription.id,
amount: '9.99', // or 'max-remaining-charge'
testnet: true
});
// Execute the charge using your wallet provider
// (This step requires your app's wallet to execute the transaction)
For applications that need full wallet connectivity and blockchain interactions beyond payments:
# npm
npm install @base-org/account
# yarn
yarn add @base-org/account
Note: The following sections apply only to the full Base Account SDK functionality. For payments and subscriptions, use the standalone functions shown above.
-
Compare the installed version with the latest:
# yarn yarn outdated @base-org/account # npm npm outdated @base-org/account
-
Update to latest:
# yarn yarn upgrade @base-org/account --latest # npm npm update @base-org/account
-
Initialize the SDK
const sdk = createBaseAccountSDK({ appName: 'SDK Playground', });
-
Make Base Account Provider
const provider = sdk.getProvider();
-
Request accounts to initialize a connection to wallet
const addresses = provider.request({ method: 'eth_requestAccounts', });
-
Make more requests
provider.request('personal_sign', [ `0x${Buffer.from('test message', 'utf8').toString('hex')}`, addresses[0], ]);
-
Handle provider events
provider.on('connect', (info) => { setConnect(info); }); provider.on('disconnect', (error) => { setDisconnect({ code: error.code, message: error.message }); }); provider.on('accountsChanged', (accounts) => { setAccountsChanged(accounts); }); provider.on('chainChanged', (chainId) => { setChainChanged(chainId); }); provider.on('message', (message) => { setMessage(message); });
-
The Base Account SDK test app can be viewed here https://base.github.io/account-sdk/.
-
To run it locally follow these steps:
- Fork this repo and clone it
- From the root dir run
yarn install
- From the root dir run
yarn dev