Setup
Get CDP Credentials
Get your CDP API key and wallet secret from the CDP Portal
The Go SDK requires Go 1.21 or higher.
Running Examples
The Go examples use a CLI-style interface. Run examples using:send_transaction- Create an EVM account and send a transactionsend_user_operation- Create a smart account and send a user operation
Example Usage
Send Transaction Example
This example demonstrates the complete flow of creating an EVM account, funding it, and sending a transaction.send_transaction.go - Complete transaction flow
send_transaction.go - Complete transaction flow
send_transaction.go
- Initializes CDP client from environment variables
- Creates or retrieves an EVM account by name
- Requests testnet ETH from Base Sepolia faucet
- Creates and signs a transaction using RLP encoding
- Broadcasts the signed transaction to the network
- Waits for transaction confirmation
createCDPClient()- Initializes the CDP client with credentialsgetOrCreateEvmAccount()- Idempotent account creationfaucetEVMAccount()- Requests testnet fundscreateAndSignEVMTransaction()- Creates and signs EIP-1559 transactionsendSignedEVMTransaction()- Broadcasts transaction and waits for confirmation
go run . send_transactionSend User Operation Example
This example demonstrates creating and using an EIP-4337 smart account to send gasless transactions.send_user_operation.go - Smart account user operations
send_user_operation.go - Smart account user operations
send_user_operation.go
- Creates an EOA (Externally Owned Account) as the smart account owner
- Creates or retrieves an EIP-4337 smart account
- Funds the smart account with testnet ETH
- Prepares and sends a user operation (gasless transaction)
- Returns the user operation hash and explorer link
getOrCreateSmartAccount()- Creates smart account with specified ownerprepareAndSendUserOperation()- Constructs and sends user operationparseEther()- Converts ETH amount to wei
- Gas sponsorship (gasless transactions on Base Sepolia)
- Batch operations (multiple calls in one user operation)
- Social recovery capabilities
- Custom validation logic
go run . send_user_operationMain Entry Point
main.go - CLI router for examples
main.go - CLI router for examples
main.go
- Provides a simple CLI interface for running examples
- Routes to the appropriate example function based on command-line argument
- Displays usage information if no argument is provided
Key Concepts
Client Initialization
The CDP Go client uses environment variables for configuration:Idempotent Operations
Both examples use a get-or-create pattern for idempotency:Error Handling
The examples demonstrate proper error handling patterns:Transaction Encoding
EVM transactions are RLP-encoded before signing:Integration with go-ethereum
The examples use the popular go-ethereum library for blockchain operations:Testing Networks
The examples use Base Sepolia testnet:- Network: Base Sepolia
- Chain ID: 84532
- RPC: https://sepolia.base.org
- Explorer: https://sepolia.basescan.org
- Faucet: Automatic via
RequestEvmFaucetAPI
On Base Sepolia, gas for smart account user operations is automatically sponsored by CDP.
Project Structure
Dependencies
The examples use these key dependencies:Full Example List
View all examples in the repository:Browse Go Examples
View all Go examples on GitHub
Next Steps
Go SDK Reference
Explore the full Go SDK API
TypeScript Examples
See TypeScript examples
Python Examples
View Python examples
Rust Examples
Check Rust examples
Additional Resources
go-ethereum Docs
Learn about the go-ethereum library
EIP-4337
Read about Account Abstraction
Base Sepolia
Base Sepolia testnet documentation
CDP Portal
Get your API credentials