https://github.com/coinbase/staking-client-library-ts
Programmatic access to Coinbase's best-in-class staking infrastructure and services. 🔵
https://github.com/coinbase/staking-client-library-ts
rewards staking
Last synced: 2 months ago
JSON representation
Programmatic access to Coinbase's best-in-class staking infrastructure and services. 🔵
- Host: GitHub
- URL: https://github.com/coinbase/staking-client-library-ts
- Owner: coinbase
- License: apache-2.0
- Created: 2023-10-04T00:26:50.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-31T18:09:16.000Z (6 months ago)
- Last Synced: 2025-03-31T19:24:45.427Z (6 months ago)
- Topics: rewards, staking
- Language: TypeScript
- Homepage: https://github.com/coinbase/staking-client-library-ts
- Size: 356 KB
- Stars: 18
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# [Coinbase Staking API](https://github.com/coinbase/staking-client-library-ts)
> Programmatic access to Coinbase's best-in-class staking infrastructure and services. :large_blue_circle:
[](https://badge.fury.io/js/@coinbase%2Fstaking-client-library-ts) [](https://github.com/coinbase/staking-client-library-ts/releases) [](https://github.com/coinbase/staking-client-library-ts/graphs/contributors) [](https://github.com/coinbase/staking-client-library-ts/stargazers) [](https://github.com/coinbase/staking-client-library-ts/blob/main/LICENSE)
## Overview
`staking-client-library-ts` is the Typescript SDK for the **Coinbase Staking API** :large_blue_circle:.
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 :sparkles:.
## Quick Start
Prerequisite: [Node 20+](https://www.npmjs.com/package/node/v/20.11.1)
1. In a fresh directory, run:
```shell
npm install @coinbase/staking-client-library-ts
```2. Copy and paste a code sample from below or any other [example](./examples/) into an `example.ts` file.
3. Create a new API Key in the [portal](https://portal.cdp.coinbase.com/access/api) and paste the API Key name and private key into the example.
4. Run :rocket:
```shell
npx ts-node example.ts
```### Stake Partial ETH :diamond_shape_with_a_dot_inside:
This code sample helps stake partial ETH (non-multiples of 32 ETH). View the full source [here](examples/ethereum/create-workflow.ts)
```typescript
// examples/ethereum/create-workflow.ts
import { StakingClient } from "@coinbase/staking-client-library-ts";// Set your api key name and private key here. Get your keys from here: https://portal.cdp.coinbase.com/access/api
const apiKeyName: string = 'your-api-key-name';
const apiPrivateKey: string = 'your-api-private-key';const client = new StakingClient(apiKeyName, apiPrivateKey);
client.Ethereum.stake('holesky', '0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE', '123')
.then((workflow) => {
console.log(JSON.stringify(workflow, null, 2));
})
.catch(() => {
throw new Error('Error running stake action on ethereum');
});
```
Output```text
{
"name": "workflows/baecd951-838f-44ec-b7b5-20e1820c09dc",
"action": "protocols/ethereum_kiln/networks/holesky/actions/stake",
"ethereumKilnStakingParameters": {
"stakeParameters": {
"stakerAddress": "0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE",
"integratorContractAddress": "0xA55416de5DE61A0AC1aa8970a280E04388B1dE4b",
"amount": {
"value": "123",
"currency": "ETH"
}
}
},
"state": "STATE_WAITING_FOR_EXT_BROADCAST",
"currentStepId": 0,
"steps": [
{
"name": "stake tx",
"txStepOutput": {
"unsignedTx": "02f3824268068502540be4008503c1b8346683061a8094a55416de5de61a0ac1aa8970a280e04388b1de4b7b843a4b66f1c0808080",
"signedTx": "",
"txHash": "",
"state": "STATE_PENDING_EXT_BROADCAST",
"errorMessage": ""
}
}
],
"createTime": "2024-05-08T15:24:57.480231386Z",
"updateTime": "2024-05-08T15:24:57.480231386Z",
"completeTime": null
}
```
### Stake SOL :diamond_shape_with_a_dot_inside:
This code sample helps stake SOL from a given user wallet. View the full source [here](examples/solana/create-workflow.ts)
```typescript
// examples/solana/create-workflow.ts
import { StakingClient } from "@coinbase/staking-client-library-ts";// Set your api key name and private key here. Get your keys from here: https://portal.cdp.coinbase.com/access/api
const apiKeyName: string = 'your-api-key-name';
const apiPrivateKey: string = 'your-api-private-key';const client = new StakingClient(apiKeyName, apiPrivateKey);
client.Solana.stake('devnet', '8rMGARtkJY5QygP1mgvBFLsE9JrvXByARJiyNfcSE5Z', '100000000')
.then((workflow) => {
console.log(JSON.stringify(workflow, null, 2));
})
.catch(() => {
throw new Error('Error running stake action on solana');
});
```
Output```text
{
"name": "workflows/2cd484db-56fe-4c8b-a53d-8039c8f27547",
"action": "protocols/solana/networks/devnet/actions/stake",
"solanaStakingParameters": {
"stakeParameters": {
"walletAddress": "8rMGARtkJY5QygP1mgvBFLsE9JrvXByARJiyNfcSE5Z",
"validatorAddress": "GkqYQysEGmuL6V2AJoNnWZUz2ZBGWhzQXsJiXm2CLKAN",
"amount": {
"value": "100000000",
"currency": "SOL"
},
"priorityFee": {
"computeUnitLimit": "0",
"unitPrice": "0"
}
}
},
"state": "STATE_WAITING_FOR_EXT_BROADCAST",
"currentStepId": 0,
"steps": [
{
"name": "stake tx",
"txStepOutput": {
"unsignedTx": "66hEYYWnwGWkGpMKF2H2sCzxnmoAfY8LPnYMgWdY6rC7hX2H6DEE2YdPxECFx8FeeNmea8N87L4KuZ6dirYXZi9XNr5uPJdf8W1jdShcSwzSmmqz4SA7dmFjdTM19hNEu7hMMF7C2Vcm8zka9FErt4wyshJNXYXM6cbJ8UUypGAb8g4vQDMoVavSiVFWxMGE5Sv7JL2gXkFEz2UbxvX7t6W2UbhDtt7545km4rQtFcrMTahmaoqaTMysLuoMcJpzps1c7pCigthYYcBN7yxF4zVZHJHbMXqFuap1BAb2MCYeBxk4krzGJNR3Avo6seVVthxMLHqExv8Yzrdvufn61xv6S4DGQdhbbUM2auGi5b45bkJ4EEHKMhEXqXWrYHSQQMbtgJ2EP4zNiSK8avPREuUQS4BS1aRUF3zT8bkEfWDfp5EjxAs6fumYZCkRKsyjRHEZMN6m9fwESmJqdJPeTJUrZkkvhJZCszPdeTNxSzrUnaeQ2oLvmw29MXVzdvx9gzpa1AKP9YcWjjbZGBkBrYnKzS6KkDBvi2uvo633eqJCrMzRDrVsvQPAi9kTQcqMFt567WotqbF9EBhfAKMss9G9eHXeVCGPa7P2kG9Whix2adaatpi6B6yUjfHFKwXNyXrTUM5UnjCBW9PoLyjPve8q6x6HqVb63v97B29HjguuEZhMjrMctXpPB4EVhemczKitdsYaQRFzsV1R3XVHnfha2BwTyw5B9U7uYFqdrfKwwszni5aqvAsSV3YwGEuwMrZSaCYVub5DtDaqKiJee138tGsn16bg6seb5jZeEiguaAmwDrXY9nT4ihvh4Gqtao4BoipSvb3vQJsjG4KAxTQWb3HFqQXUoVrs81sRh64amtg7or4Pwj8F5fMwx6VyqHW8BbfA4CaXrfunWLKo5Qap1gNnaV9WxoN9n9bKsJ9fS2PQgtX",
"signedTx": "",
"txHash": "",
"state": "STATE_PENDING_EXT_BROADCAST",
"errorMessage": ""
}
}
],
"createTime": "2024-05-08T15:25:58.265307812Z",
"updateTime": "2024-05-08T15:25:58.265307812Z",
"completeTime": null
}
```
### View Partial ETH Rewards :moneybag:
This code sample helps view rewards for an Ethereum address. View the full source [here](examples/ethereum/list-rewards/partial-eth.ts).
```typescript
// examples/ethereum/list-rewards/partial-eth.ts
import { StakingClient } from "@coinbase/staking-client-library-ts";// Set your api key name and private key here. Get your keys from here: https://portal.cdp.coinbase.com/access/api
const apiKeyName: string = 'your-api-key-name';
const apiPrivateKey: string = 'your-api-private-key';const client = new StakingClient(apiKeyName, apiPrivateKey);
// Defines which address and rewards we want to see
const address: string =
'0x60c7e246344ae3856cf9abe3a2e258d495fc39e0';
const filter: string = `address='${address}' AND period_end_time > '2024-05-01T00:00:00Z' AND period_end_time < '2024-05-02T00:00:00Z'`;// Loops through rewards array and prints each reward
var list = async function () {
const resp = await client.Ethereum.listRewards(filter)
resp.rewards!.forEach((reward) => {
console.log(JSON.stringify(reward, null, 2));
});
}list();
```
Output```json
{
"address": "0x60c7e246344ae3856cf9abe3a2e258d495fc39e0",
"date": "2024-05-01",
"aggregationUnit": "DAY",
"periodStartTime": "2024-05-01T00:00:00Z",
"periodEndTime": "2024-05-01T23:59:59Z",
"totalEarnedNativeUnit": {
"amount": "0.001212525541415161",
"exp": "18",
"ticker": "ETH",
"rawNumeric": "1212525541415161"
},
"totalEarnedUsd": [
{
"source": "COINBASE_EXCHANGE",
"conversionTime": "2024-05-02T00:09:00Z",
"amount": {
"amount": "3.61",
"exp": "2",
"ticker": "USD",
"rawNumeric": "361"
},
"conversionPrice": "2971.419922"
}
],
"endingBalance": null,
"protocol": "ethereum",
"rewardState": "PENDING_CLAIMABLE"
}
```
## Documentation
There are numerous examples in the [`examples directory`](./examples) to help get you started. For even more, refer to our [documentation website](https://docs.cdp.coinbase.com/staking/docs/welcome) for detailed definitions, [API specification](https://docs.cdp.coinbase.com/staking/reference), integration guides, and more!
## Contributing
Thanks for considering contributing to the project! Please refer to [our contribution guide](./CONTRIBUTING.md).
## Contact Us
If you have any questions, please reach out to us in the #staking channel on our [Discord](https://discord.com/invite/cdp) server.