Programmatic access to Coinbase's best-in-class staking infrastructure and services. π΅
staking-client-library-ts
is the Typescript SDK for the Coinbase Staking API π΅.
The Coinbase Staking API empowers developers to deliver a fully-featured staking experience in their Web2 apps, wallets, or dApps using one common interface across protocols.
A traditional infrastructure-heavy staking integration can take months. Coinbase's Staking API enables onboarding within hours β¨.
Prerequisite: Node 20+
- Install this package:
npm install @coinbase/staking-client-library-ts
- Create and download an API key from the Cloud Platform.
- Place the key named
.coinbase_cloud_api_key.json
at the root of this repository. - Run one of the code samples below or any of our provided examples π.
This code sample creates an ETH staking workflow. View the full code sample here
Code Sample
// examples/ethereum/create-workflow.ts
import { StakingClient } from "@coinbase/staking-client-library-ts";
const client = new StakingClient();
client.Ethereum.stake(
'holesky',
true,
'0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE', // replace with your wallet address
'0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b',
'123',
)
.then((workflow) => {
console.log('Workflow created %s', workflow.name);
})
.catch(() => {
throw new Error(`Error creating workflow`);
});
Output
Workflow created: projects/62376b2f-3f24-42c9-9025-d576a3c06d6f/workflows/ffbf9b45-c57b-49cb-a4d5-fdab66d8cb25
This code sample returns rewards for an Ethereum validator address. View the full code sample here.
Code Sample
import { StakingClient } from "@coinbase/staking-client-library-ts";
// Defines which address and rewards we want to see
const address: string =
'0xac53512c39d0081ca4437c285305eb423f474e6153693c12fbba4a3df78bcaa3422b31d800c5bea71c1b017168a60474';
const filter: string = `address='${address}' AND period_end_time > '2024-02-25T00:00:00Z' AND period_end_time < '2024-02-27T00:00:00Z'`;
const client = new StakingClient();
// Loops through rewards array and prints each reward
client.Ethereum.listRewards(filter).then((resp) => {
resp.rewards!.forEach((reward) => {
console.log(JSON.stringify(reward, null, 2));
});
});
Output
{
"address": "0xac53512c39d0081ca4437c285305eb423f474e6153693c12fbba4a3df78bcaa3422b31d800c5bea71c1b017168a60474",
"date": "2024-02-25",
"aggregationUnit": "DAY",
"periodStartTime": "2024-02-25T00:00:00Z",
"periodEndTime": "2024-02-25T23:59:59Z",
"totalEarnedNativeUnit": {
"amount": "0.002183619",
"exp": "18",
"ticker": "ETH",
"rawNumeric": "2183619000000000"
},
"totalEarnedUsd": [
{
"source": "COINBASE_EXCHANGE",
"conversionTime": "2024-02-26T00:09:00Z",
"amount": {
"amount": "6.79",
"exp": "2",
"ticker": "USD",
"rawNumeric": "679"
},
"conversionPrice": "3105.780029"
}
],
"endingBalance": null,
"protocol": "ethereum"
}
{
"address": "0xac53512c39d0081ca4437c285305eb423f474e6153693c12fbba4a3df78bcaa3422b31d800c5bea71c1b017168a60474",
"date": "2024-02-26",
"aggregationUnit": "DAY",
"periodStartTime": "2024-02-26T00:00:00Z",
"periodEndTime": "2024-02-26T23:59:59Z",
"totalEarnedNativeUnit": {
"amount": "0.002182946",
"exp": "18",
"ticker": "ETH",
"rawNumeric": "2182946000000000"
},
"totalEarnedUsd": [
{
"source": "COINBASE_EXCHANGE",
"conversionTime": "2024-02-27T00:09:00Z",
"amount": {
"amount": "6.94",
"exp": "2",
"ticker": "USD",
"rawNumeric": "694"
},
"conversionPrice": "3178.889893"
}
],
"endingBalance": null,
"protocol": "ethereum"
}
There are numerous examples in the examples directory
to help get you started. For even more, refer to our documentation website for detailed definitions, API specifications, integration guides, and more!