What you will learn
- Installing the CDP SDK
- How to check your stakeable balance
- How to create a transaction to stake Hoodi ETH
- How to sign and broadcast a staking transaction
1. Prerequisites
- TypeScript
- Go
The Coinbase Typescript SDK requires Node.js version 18+. To verify your Node version:
2. API Key Setup
To use the CDP SDK, you need a CDP secret API key. If you need to create one, follow this guide. Once you have the key, you can either save it as a file on your filesystem (if you downloaded it) or use the key details as environment variables. You will need to reference this later in your code.Optional API Key File DownloadFor enhanced security, API key files are no longer automatically downloaded. If you need to reference your API key via file path in your code, click the Download API key button in the modal to save the key file. Otherwise, you can copy the key details directly from the modal and use them as environment variables (recommended for better security).
3. Create a Workspace
In your preferred shell, create a new directory:4. Install the CDP SDK
- TypeScript
- Go
Install the CDP SDK using your preferred package manager:
5. Create a Staking Transaction
To proceed with the stake example below, you need some Hoodi ETH in your wallet. If you don’t have any, you can request some from the Ethereum Hoodi Faucet.- TypeScript
- Go
Create a new file named Then run the code to create a staking transaction:
stake.ts and paste the code block below:stake.ts
Note
- Be sure to replace the placeholder values with your own for:
Sample output
Sample output
6. Sign and Broadcast your Staking Transaction
The previous step generated an unsigned transaction. To stake successfully, the transaction needs to be signed and broadcasted to the network. Signing and broadcasting functionality is added to the example from above. The additional lines are highlighted for clarity.- TypeScript
- Go
showLineNumbers stake.ts
Note
- Be sure to replace the placeholder values with your own for:
Sample output
Sample output
You should see the transaction being created, signed, and then broadcast to the network: