Skip to content

Commit

Permalink
feat: add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
roushou committed Jun 21, 2024
1 parent 475d44d commit 8fcb99c
Show file tree
Hide file tree
Showing 23 changed files with 322 additions and 8 deletions.
7 changes: 7 additions & 0 deletions examples/onchain_list-address-transactions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List address transactions - Onchain Data

Run

```sh
$ bun run index.ts
```
15 changes: 15 additions & 0 deletions examples/onchain_list-address-transactions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createClient } from "@coinbase-platform/onchain";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const client = createClient({ apiKey });

const response = await client.listAddressTransactions([
{
address: "0x0e73fc61bb9d6b7588910c2d14e83bae68222c5d",
pageSize: 2,
},
]);

console.log(response);
12 changes: 12 additions & 0 deletions examples/onchain_list-address-transactions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@examples/onchain_list-address-transactions",
"private": true,
"module": "index.ts",
"type": "module",
"dependencies": {
"@coinbase-platform/onchain": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/onchain_list-address-transactions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/onchain_list-balance-details/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List balance details - Onchain Data

Run

```sh
$ bun run index.ts
```
16 changes: 16 additions & 0 deletions examples/onchain_list-balance-details/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createClient } from "@coinbase-platform/onchain";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const client = createClient({ apiKey });

const response = await client.listBalanceDetails([
{
address: "1dice6GV5Rz2iaifPvX7RMjfhaNPC8SXH",
assetId: "6ecc0dcc-10a2-500e-b315-a3b9abae19ce",
pageSize: 1,
},
]);

console.log(response);
12 changes: 12 additions & 0 deletions examples/onchain_list-balance-details/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@examples/onchain_list-balance-details",
"private": true,
"module": "index.ts",
"type": "module",
"dependencies": {
"@coinbase-platform/onchain": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/onchain_list-balance-details/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/onchain_list-balance-histories/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List balance histories - Onchain Data

Run

```sh
$ bun run index.ts
```
15 changes: 15 additions & 0 deletions examples/onchain_list-balance-histories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createClient } from "@coinbase-platform/onchain";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const client = createClient({ apiKey });

const response = await client.listBalanceHistories([
{
address: "0x0e73fc61bb9d6b7588910c2d14e83bae68222c5d",
assetId: "123d82ca-b3f4-527c-ace7-559d5791a564",
},
]);

console.log(response);
12 changes: 12 additions & 0 deletions examples/onchain_list-balance-histories/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@examples/onchain_list-balance-histories",
"private": true,
"module": "index.ts",
"type": "module",
"dependencies": {
"@coinbase-platform/onchain": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/onchain_list-balance-histories/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/onchain_list-balances/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List balances - Onchain Data

Run

```sh
$ bun run index.ts
```
15 changes: 15 additions & 0 deletions examples/onchain_list-balances/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createClient } from "@coinbase-platform/onchain";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const client = createClient({ apiKey });

const response = await client.listBalances([
{
address: "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789",
pageSize: 1,
},
]);

console.log(response);
12 changes: 12 additions & 0 deletions examples/onchain_list-balances/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@examples/onchain_list-balances",
"private": true,
"module": "index.ts",
"type": "module",
"dependencies": {
"@coinbase-platform/onchain": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/onchain_list-balances/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
7 changes: 7 additions & 0 deletions examples/onchain_rpc-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# RPC client- Onchain Data

Run

```sh
$ bun run index.ts
```
18 changes: 18 additions & 0 deletions examples/onchain_rpc-client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createRpcClient } from "@coinbase-platform/onchain";

const apiKey = process.env.API_KEY;
if (!apiKey) throw new Error("API_KEY not found");

const rpc = createRpcClient({ apiKey });

const response = await rpc.request({
method: "cdp_listBalances",
parameters: [
{
address: "0x0e73fc61bb9d6b7588910c2d14e83bae68222c5d",
pageSize: 2,
},
],
});

console.log(response);
12 changes: 12 additions & 0 deletions examples/onchain_rpc-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@examples/onchain_rpc-client",
"private": true,
"module": "index.ts",
"type": "module",
"dependencies": {
"@coinbase-platform/onchain": "workspace:*"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
27 changes: 27 additions & 0 deletions examples/onchain_rpc-client/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}
10 changes: 2 additions & 8 deletions packages/onchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
"publishConfig": {
"access": "public"
},
"keywords": [
"coinbase",
"coinbase platform"
],
"keywords": ["coinbase", "coinbase platform"],
"scripts": {
"build": "pnpm clean && tsup",
"clean": "rimraf ./dist",
Expand All @@ -49,10 +46,7 @@
},
"./package.json": "./package.json"
},
"files": [
"src",
"dist"
],
"files": ["src", "dist"],
"engine": {
"node": "^18.0.0 || >=20.0.0"
}
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- 'packages/*'
- 'examples/*'

0 comments on commit 8fcb99c

Please sign in to comment.