Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 0 additions & 63 deletions v2/create_earn_account/TESTING.md

This file was deleted.

4 changes: 4 additions & 0 deletions v2/create_earn_account/python/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ COMPASS_API_KEY=your_compass_api_key_here
# Wallet Configuration
# The wallet address that will own the Earn Account and pay for gas
WALLET_ADDRESS=0xYourWalletAddress
PRIVATE_KEY=your_wallet_private_key_here

# Base RPC Configuration
BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/your-api-key
14 changes: 10 additions & 4 deletions v2/create_earn_account/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ This example demonstrates how to create an Earn Account using the Compass API Py

1. Install dependencies (make sure you have the latest version):
```bash
pip install --upgrade compass-api-sdk python-dotenv
pip install --upgrade compass-api-sdk python-dotenv web3 eth-account
```

Or if using `uv`:
```bash
uv pip install compass-api-sdk python-dotenv
uv pip install compass-api-sdk python-dotenv web3 eth-account
```

**Note:** This example requires `compass-api-sdk` version 2.0.1 or later (which includes the `earn` endpoints). Make sure to upgrade if you have an older version.
Expand All @@ -29,6 +29,8 @@ cp .env.example .env
3. Fill in your `.env` file with your actual values:
- `COMPASS_API_KEY`: Your Compass API key
- `WALLET_ADDRESS`: Your wallet address (will own the Earn Account)
- `PRIVATE_KEY`: Your wallet's private key (to sign the transaction)
- `BASE_RPC_URL`: Your Base mainnet RPC URL (to broadcast the transaction)

## Run

Expand All @@ -38,12 +40,16 @@ python main.py

## What This Does

This example gets an unsigned transaction to create an Earn Account on Base. The transaction must be signed and broadcast separately.
This example:
1. Gets an unsigned transaction to create an Earn Account on Base
2. Signs the transaction with your private key
3. Broadcasts it to the Base network
4. Waits for confirmation

## Notes

- **No Gas Sponsorship**: The `owner` (who controls the account) is also the `sender` (who pays for gas). Note that Earn Account creation can also be done WITH gas sponsorship (using the `/gas_sponsorship/prepare` endpoint), but this example does not use gas sponsorship.
- The Earn Account address is deterministic and returned before the transaction is confirmed.
- This example only retrieves the unsigned transaction. You'll need to sign and broadcast it separately.
- Make sure your wallet has enough ETH on Base to cover gas fees.
- **Important:** Requires `compass-api-sdk` version 2.0.1 or later (includes `earn` endpoints). Make sure to install the latest version.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Metadata-Version: 2.4
Name: create_earn_account_python_example
Version: 1.0.0
Summary: Example: Create an Earn Account using Compass API
Requires-Dist: compass-api-sdk
Requires-Dist: python-dotenv
Requires-Dist: web3
Requires-Dist: eth-account
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
README.md
main.py
pyproject.toml
create_earn_account_python_example.egg-info/PKG-INFO
create_earn_account_python_example.egg-info/SOURCES.txt
create_earn_account_python_example.egg-info/dependency_links.txt
create_earn_account_python_example.egg-info/requires.txt
create_earn_account_python_example.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compass-api-sdk
python-dotenv
web3
eth-account
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
24 changes: 14 additions & 10 deletions v2/create_earn_account/python/main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
# SNIPPET START 1
# Import Libraries & Environment Variables
from compass_api_sdk import CompassAPI, models
import os
from dotenv import load_dotenv
from web3 import Web3

load_dotenv()

COMPASS_API_KEY = os.getenv("COMPASS_API_KEY")
WALLET_ADDRESS = os.getenv("WALLET_ADDRESS")
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
BASE_RPC_URL = os.getenv("BASE_RPC_URL")
# SNIPPET END 1

# SNIPPET START 2
# Initialize Compass SDK
compass = CompassAPI(api_key_auth=COMPASS_API_KEY)
with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api:
# SNIPPET END 2

# SNIPPET START 3
# Create Earn Account (No Gas Sponsorship)
# Get unsigned transaction to create an Earn Account on Base
# owner: The address that will own and control the Earn Account
# sender: The address that will sign and pay for gas (same as owner = no gas sponsorship)
with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api:
# Get unsigned transaction to create Earn Account
create_account_response = compass_api.earn.earn_create_account(
chain=models.CreateAccountRequestChain.BASE,
sender=WALLET_ADDRESS,
owner=WALLET_ADDRESS,
estimate_gas=True,
)
# SNIPPET END 3

# SNIPPET START 4
# Sign and broadcast transaction
w3 = Web3(Web3.HTTPProvider(BASE_RPC_URL))
tx_dict = create_account_response.model_dump(by_alias=True)
signed_tx = w3.eth.account.sign_transaction(tx_dict["transaction"], PRIVATE_KEY)
tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
w3.eth.wait_for_transaction_receipt(tx_hash)
print("Earn Account Address:", create_account_response.earn_account_address)
print("Unsigned Transaction:", create_account_response.transaction)
# SNIPPET END 3
# SNIPPET END 4

2 changes: 2 additions & 0 deletions v2/create_earn_account/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ description = "Example: Create an Earn Account using Compass API"
dependencies = [
"compass-api-sdk",
"python-dotenv",
"web3",
"eth-account",
]

4 changes: 4 additions & 0 deletions v2/create_earn_account/typescript/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ COMPASS_API_KEY=your_compass_api_key_here
# Wallet Configuration
# The wallet address that will own the Earn Account and pay for gas
WALLET_ADDRESS=0xYourWalletAddress
PRIVATE_KEY=your_wallet_private_key_here

# Base RPC Configuration
BASE_RPC_URL=https://base-mainnet.g.alchemy.com/v2/your-api-key
10 changes: 8 additions & 2 deletions v2/create_earn_account/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cp .env.example .env
3. Fill in your `.env` file with your actual values:
- `COMPASS_API_KEY`: Your Compass API key
- `WALLET_ADDRESS`: Your wallet address (will own the Earn Account)
- `PRIVATE_KEY`: Your wallet's private key (to sign the transaction)
- `BASE_RPC_URL`: Your Base mainnet RPC URL (to broadcast the transaction)

## Run

Expand All @@ -37,11 +39,15 @@ npm start

## What This Does

This example gets an unsigned transaction to create an Earn Account on Base. The transaction must be signed and broadcast separately.
This example:
1. Gets an unsigned transaction to create an Earn Account on Base
2. Signs the transaction with your private key
3. Broadcasts it to the Base network
4. Waits for confirmation

## Notes

- **No Gas Sponsorship**: The `owner` (who controls the account) is also the `sender` (who pays for gas). Note that Earn Account creation can also be done WITH gas sponsorship (using the `/gas_sponsorship/prepare` endpoint), but this example does not use gas sponsorship.
- The Earn Account address is deterministic and returned before the transaction is confirmed.
- This example only retrieves the unsigned transaction. You'll need to sign and broadcast it separately.
- Make sure your wallet has enough ETH on Base to cover gas fees.

3 changes: 2 additions & 1 deletion v2/create_earn_account/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"description": "Example: Create an Earn Account using Compass API",
"dependencies": {
"@compass-labs/api-sdk": "^1.0.26",
"dotenv": "^16.5.0"
"dotenv": "^16.5.0",
"viem": "^2.31.0"
},
"devDependencies": {
"@types/node": "^24.0.0",
Expand Down
39 changes: 31 additions & 8 deletions v2/create_earn_account/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,57 @@
// SNIPPET START 1
// Import Libraries & Environment Variables
import { CompassApiSDK } from "@compass-labs/api-sdk";
import dotenv from "dotenv";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { http, createWalletClient, createPublicClient } from "viem";

dotenv.config();

const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string;
const WALLET_ADDRESS = process.env.WALLET_ADDRESS as `0x${string}`;
const PRIVATE_KEY = process.env.PRIVATE_KEY as `0x${string}`;
const BASE_RPC_URL = process.env.BASE_RPC_URL as string;
// SNIPPET END 1

// SNIPPET START 2
// Initialize Compass SDK
const compass = new CompassApiSDK({
apiKeyAuth: COMPASS_API_KEY,
});
// SNIPPET END 2

// SNIPPET START 3
// Create Earn Account (No Gas Sponsorship)
// Get unsigned transaction to create an Earn Account on Base
// owner: The address that will own and control the Earn Account
// sender: The address that will sign and pay for gas (same as owner = no gas sponsorship)
// Get unsigned transaction to create Earn Account
const createAccountResponse = await compass.earn.earnCreateAccount({
chain: "base",
sender: WALLET_ADDRESS,
owner: WALLET_ADDRESS,
estimateGas: true,
});
// SNIPPET END 3

// SNIPPET START 4
// Sign and broadcast transaction
const account = privateKeyToAccount(PRIVATE_KEY);
const walletClient = createWalletClient({
account,
chain: base,
transport: http(BASE_RPC_URL),
});
const publicClient = createPublicClient({
chain: base,
transport: http(BASE_RPC_URL),
});

const transaction = createAccountResponse.transaction as any;
const txHash = await walletClient.sendTransaction({
...transaction,
value: BigInt(transaction.value || 0),
gas: BigInt(transaction.gas),
maxFeePerGas: BigInt(transaction.maxFeePerGas),
maxPriorityFeePerGas: BigInt(transaction.maxPriorityFeePerGas),
});

await publicClient.waitForTransactionReceipt({ hash: txHash });
console.log("Earn Account Address:", createAccountResponse.earnAccountAddress);
console.log("Unsigned Transaction:", createAccountResponse.transaction);
// SNIPPET END 3
// SNIPPET END 4

58 changes: 58 additions & 0 deletions v2/fund_earn_account/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Fund Earn Account - Python Example

This example demonstrates how to fund an Earn Account by transferring USDC from your wallet to the Earn Account using the Compass API Python SDK.

## Prerequisites

- Python 3.8+ installed
- A Compass API key ([Get one here](https://auth-compasslabs-ai.auth.eu-west-2.amazoncognito.com/login?client_id=2l366l2b3dok7k71nbnu8r1u36&redirect_uri=https://api.compasslabs.ai/auth/callback&response_type=code&scope=openid+email+profile))
- An existing Earn Account
- USDC balance in your wallet on Base

## Setup

1. Install dependencies:
```bash
pip install -e .
```

Or install directly:
```bash
pip install compass-api-sdk python-dotenv web3 eth-account
```

**Note:** Make sure you have `compass-api-sdk` version 2.0.1 or later.

2. Copy the example environment file:
```bash
cp .env.example .env
```

3. Fill in your `.env` file with your actual values:
- `COMPASS_API_KEY`: Your Compass API key
- `WALLET_ADDRESS`: Your wallet address (owner of the Earn Account)
- `PRIVATE_KEY`: Your wallet's private key (to sign the transaction)
- `BASE_RPC_URL`: Your Base mainnet RPC URL (to broadcast the transaction)

## Run

```bash
python main.py
```

## What This Does

This example:
1. Gets an unsigned transaction to transfer 2 USDC from your wallet to your Earn Account
2. Signs the transaction with your private key
3. Broadcasts it to the Base network
4. Waits for confirmation

## Notes

- This example transfers 2 USDC from your wallet to your Earn Account
- The `owner` must be the address that owns the Earn Account
- Make sure your wallet has sufficient USDC balance on Base
- Make sure your wallet has enough ETH on Base to cover gas fees
- Gas sponsorship is disabled (`gas_sponsorship=False`)

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Metadata-Version: 2.4
Name: fund_earn_account_python_example
Version: 1.0.0
Summary: Example: Fund Earn Account (Transfer USDC) using Compass API
Requires-Dist: compass-api-sdk
Requires-Dist: python-dotenv
Requires-Dist: web3
Requires-Dist: eth-account
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
README.md
main.py
pyproject.toml
fund_earn_account_python_example.egg-info/PKG-INFO
fund_earn_account_python_example.egg-info/SOURCES.txt
fund_earn_account_python_example.egg-info/dependency_links.txt
fund_earn_account_python_example.egg-info/requires.txt
fund_earn_account_python_example.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
compass-api-sdk
python-dotenv
web3
eth-account
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
Loading
Loading