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: 63 additions & 0 deletions v2/create_earn_account/TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Testing Guide

Test both TypeScript and Python versions before pushing.

## Prerequisites

1. Create `.env` files in both directories with your actual values:
- `COMPASS_API_KEY`: Your Compass API key
- `WALLET_ADDRESS`: Your wallet address (0x...)

## Test TypeScript

```bash
cd typescript

# Make sure .env file exists (copy from .env.example and fill in values)
cp .env.example .env
# Edit .env with your actual values

# Run the script
npm run dev
```

**Expected output:**
- Earn Account Address: `0x...`
- Unsigned Transaction: `{ chainId, data, from, gas, ... }`

## Test Python

```bash
cd python

# Install dependencies (if using uv or pip)
pip install compass-api-sdk python-dotenv
# OR if using uv:
# uv pip install compass-api-sdk python-dotenv

# Make sure .env file exists
cp .env.example .env
# Edit .env with your actual values

# Run the script
python main.py
```

**Expected output:**
- Earn Account Address: `0x...`
- Unsigned Transaction: `{ chainId, data, from, gas, ... }`

## Verify Results

Both scripts should:
1. ✅ Successfully connect to Compass API
2. ✅ Return an Earn Account address
3. ✅ Return an unsigned transaction object
4. ✅ No errors

If you get errors, check:
- API key is valid
- Wallet address is correct format (0x...)
- Network connection
- SDK versions are up to date

6 changes: 6 additions & 0 deletions v2/create_earn_account/python/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Compass API Configuration
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
49 changes: 49 additions & 0 deletions v2/create_earn_account/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Create Earn Account - Python Example

This example demonstrates how to create an Earn Account using the Compass API Python SDK.

## Prerequisites

- Python 3.9+ 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))

## Setup

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

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

**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.

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 (will own the Earn Account)

## Run

```bash
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.

## 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.
- **Important:** Requires `compass-api-sdk` version 2.0.1 or later (includes `earn` endpoints). Make sure to install the latest version.

34 changes: 34 additions & 0 deletions v2/create_earn_account/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SNIPPET START 1
# Import Libraries & Environment Variables
from compass_api_sdk import CompassAPI, models
import os
from dotenv import load_dotenv

load_dotenv()

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

# SNIPPET START 2
# Initialize Compass SDK
compass = CompassAPI(api_key_auth=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)
with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api:
create_account_response = compass_api.earn.earn_create_account(
chain=models.CreateAccountRequestChain.BASE,
sender=WALLET_ADDRESS,
owner=WALLET_ADDRESS,
estimate_gas=True,
)

print("Earn Account Address:", create_account_response.earn_account_address)
print("Unsigned Transaction:", create_account_response.transaction)
# SNIPPET END 3

9 changes: 9 additions & 0 deletions v2/create_earn_account/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "create_earn_account_python_example"
version = "1.0.0"
description = "Example: Create an Earn Account using Compass API"
dependencies = [
"compass-api-sdk",
"python-dotenv",
]

6 changes: 6 additions & 0 deletions v2/create_earn_account/typescript/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Compass API Configuration
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
47 changes: 47 additions & 0 deletions v2/create_earn_account/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Create Earn Account - TypeScript Example

This example demonstrates how to create an Earn Account using the Compass API TypeScript SDK.

## Prerequisites

- Node.js 18+ 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))

## Setup

1. Install dependencies:
```bash
npm install
```

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 (will own the Earn Account)

## Run

```bash
npm run dev
```

Or build and run:
```bash
npm run build
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.

## 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.

25 changes: 25 additions & 0 deletions v2/create_earn_account/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "create_earn_account_typescript_example",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "tsc && node dist/index.js",
"dev": "ts-node --esm src/index.ts"
},
"author": "",
"license": "ISC",
"description": "Example: Create an Earn Account using Compass API",
"dependencies": {
"@compass-labs/api-sdk": "^1.0.26",
"dotenv": "^16.5.0"
},
"devDependencies": {
"@types/node": "^24.0.0",
"prettier": "^3.6.2",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
}

34 changes: 34 additions & 0 deletions v2/create_earn_account/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SNIPPET START 1
// Import Libraries & Environment Variables
import { CompassApiSDK } from "@compass-labs/api-sdk";
import dotenv from "dotenv";

dotenv.config();

const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string;
const WALLET_ADDRESS = process.env.WALLET_ADDRESS as `0x${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)
const createAccountResponse = await compass.earn.earnCreateAccount({
chain: "base",
sender: WALLET_ADDRESS,
owner: WALLET_ADDRESS,
estimateGas: true,
});

console.log("Earn Account Address:", createAccountResponse.earnAccountAddress);
console.log("Unsigned Transaction:", createAccountResponse.transaction);
// SNIPPET END 3

17 changes: 17 additions & 0 deletions v2/create_earn_account/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"lib": ["es2020"],
"module": "nodenext",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"types": ["node"]
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

Loading