Skip to content

Commit 0480899

Browse files
Add Insight API client for blockchain data access
1 parent 3f42f52 commit 0480899

40 files changed

+6860
-239
lines changed

.changeset/quick-bugs-remain.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
"@thirdweb-dev/insight": major
3+
---
4+
5+
Initial release of dedicated insight TS sdk
6+
7+
This package is a thin openAPI wrapper for insight, our in-house indexer.
8+
9+
## Configuration
10+
11+
```ts
12+
import { configure } from "@thirdweb-dev/insight";
13+
14+
// call this once at the startup of your application
15+
configure({
16+
clientId: "<YOUR_CLIENT_ID>",
17+
});
18+
```
19+
20+
## Example Usage
21+
22+
```ts
23+
import { getV1Events } from "@thirdweb-dev/insight";
24+
25+
const events = await getV1Events({
26+
query: {
27+
chain: [1, 137],
28+
filter_address: "0x1234567890123456789012345678901234567890",
29+
},
30+
});
31+
```

.changeset/wicked-pianos-carry.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
"thirdweb": minor
3+
---
4+
5+
Expose getOwnedTokens, getOwnedNFTs and getTransaction functions
6+
7+
You can now use Insight, our in-house indexer directly from the SDK with a simple API:
8+
9+
## Get Owned ERC20 tokens
10+
11+
```ts
12+
import { Insight } from "thirdweb";
13+
14+
const tokens = await Insight.getOwnedTokens({
15+
client,
16+
ownerAddress,
17+
chains: [base, polygon, arbitrum],
18+
});
19+
```
20+
21+
## Get Owned NFTs (ERC721 and ERC1155)
22+
23+
```ts
24+
import { Insight } from "thirdweb";
25+
26+
const nfts = await Insight.getOwnedNFTs({
27+
client,
28+
ownerAddress,
29+
chains: [sepolia],
30+
});
31+
```
32+
33+
## Get Transactions for a given wallet address
34+
35+
```ts
36+
import { Insight } from "thirdweb";
37+
38+
const transactions = await Insight.getTransactions({
39+
client,
40+
walletAddress,
41+
chains: [sepolia],
42+
});
43+
```
44+
45+
All functions come with extra query filters for more granular queries, refer to the documentation for more details.

.github/workflows/CI.yml

+15-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ jobs:
102102
runs-on: ubuntu-latest-8
103103
strategy:
104104
matrix:
105-
package_manager: [npm, yarn, pnpm, bun]
105+
package_manager: [pnpm] # TODO, reenable [npm, yarn, pnpm, bun]
106106
bundler: [vite, webpack, esbuild]
107107
steps:
108108
- name: Check out the code
@@ -123,7 +123,14 @@ jobs:
123123
mkdir test-project
124124
cd test-project
125125
npm init -y
126-
${{ matrix.package_manager }} add react react-dom ../packages/thirdweb
126+
127+
# Handle different package managers
128+
if [ "${{ matrix.package_manager }}" = "pnpm" ]; then
129+
# Create pnpm workspace
130+
echo '{"name": "test-project", "private": true, "workspaces": ["."]}' > package.json
131+
echo '{"packages": ["../packages/*"]}' > pnpm-workspace.yaml
132+
pnpm add react react-dom ../packages/thirdweb -w
133+
fi
127134
- name: Create test file
128135
run: |
129136
cd test-project
@@ -133,23 +140,23 @@ jobs:
133140
if: matrix.bundler == 'vite'
134141
run: |
135142
cd test-project
136-
${{matrix.package_manager}} add vite
143+
${{matrix.package_manager}} add vite -w
137144
echo 'import { defineConfig } from "vite"; import {resolve} from "path"; export default defineConfig({ build: { lib: { entry: resolve(__dirname, "index.js"), name: "e2e_test" }, outDir: "dist" }});' > vite.config.js
138145
npx vite build
139146
140147
- name: Bundle with webpack
141148
if: matrix.bundler == 'webpack'
142149
run: |
143150
cd test-project
144-
${{matrix.package_manager}} add webpack webpack-cli
151+
${{matrix.package_manager}} add webpack webpack-cli -w
145152
echo 'const path = require("path"); module.exports = { mode: "production", entry: "./index.js", output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js" }};' > webpack.config.js
146153
npx webpack
147154
148155
- name: Bundle with esbuild
149156
if: matrix.bundler == 'esbuild'
150157
run: |
151158
cd test-project
152-
${{matrix.package_manager}} add esbuild
159+
${{matrix.package_manager}} add esbuild -w
153160
npx esbuild index.js --bundle --outdir=dist
154161
155162
- name: Verify bundle
@@ -177,6 +184,9 @@ jobs:
177184
- name: Setup & Install
178185
uses: ./.github/composite-actions/install
179186

187+
- name: Build Packages
188+
run: pnpm build
189+
180190
- name: Report bundle size
181191
uses: andresz1/size-limit-action@94bc357df29c36c8f8d50ea497c3e225c3c95d1d # v1.8.0
182192
with:

apps/playground-web/src/components/pay/embed.tsx

+6-31
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,21 @@ import {
99
defineChain,
1010
treasure,
1111
} from "thirdweb/chains";
12-
import { PayEmbed, getDefaultToken } from "thirdweb/react";
12+
import { PayEmbed } from "thirdweb/react";
13+
import { StyledConnectButton } from "../styled-connect-button";
1314

1415
export function StyledPayEmbedPreview() {
1516
const { theme } = useTheme();
1617

1718
return (
1819
<div className="flex flex-col items-center justify-center">
20+
<StyledConnectButton
21+
chains={[base, defineChain(466), arbitrum, treasure, arbitrumNova]}
22+
/>
23+
<div className="h-10" />
1924
<PayEmbed
2025
client={THIRDWEB_CLIENT}
2126
theme={theme === "light" ? "light" : "dark"}
22-
connectOptions={{
23-
chains: [base, defineChain(466), arbitrum, treasure, arbitrumNova],
24-
}}
25-
supportedTokens={{
26-
466: [
27-
{
28-
address: "0x675C3ce7F43b00045a4Dab954AF36160fb57cB45",
29-
name: "USDC",
30-
symbol: "USDC",
31-
icon: getDefaultToken(base, "USDC")?.icon,
32-
},
33-
],
34-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
35-
8453: [getDefaultToken(base, "USDC")!],
36-
42161: [
37-
{
38-
address: "0x539bde0d7dbd336b79148aa742883198bbf60342",
39-
name: "MAGIC",
40-
symbol: "MAGIC",
41-
},
42-
],
43-
[arbitrumNova.id]: [
44-
{
45-
name: "Godcoin",
46-
symbol: "GOD",
47-
address: "0xb5130f4767ab0acc579f25a76e8f9e977cb3f948",
48-
icon: "https://assets.coingecko.com/coins/images/53848/standard/GodcoinTickerIcon_02.png",
49-
},
50-
],
51-
}}
5227
payOptions={{
5328
mode: "fund_wallet",
5429
metadata: {

apps/playground-web/src/components/styled-connect-button.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ export function StyledConnectButton(
3030
abstract,
3131
]}
3232
wallets={WALLETS}
33-
supportedNFTs={{
34-
"84532": ["0x638263e3eAa3917a53630e61B1fBa685308024fa"],
35-
}}
3633
client={THIRDWEB_CLIENT}
3734
theme={theme === "light" ? "light" : "dark"}
3835
{...props}

apps/portal/src/app/references/components/TDoc/utils/getSidebarLinkgroups.ts

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const tagsToGroup = {
4444
"@client": "Client",
4545
"@account": "Account",
4646
"@nebula": "Nebula",
47+
"@insight": "Insight",
4748
} as const;
4849

4950
type TagKey = keyof typeof tagsToGroup;
@@ -61,6 +62,7 @@ const sidebarGroupOrder: TagKey[] = [
6162
"@account",
6263
"@contract",
6364
"@transaction",
65+
"@insight",
6466
"@bridge",
6567
"@nebula",
6668
"@social",

packages/insight/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Insight TypeScript SDK
2+
3+
This package is a thin openAPI wrapper for insight, our in-house indexer.
4+
5+
## Configuration
6+
7+
```ts
8+
import { configure } from "@thirdweb-dev/insight";
9+
10+
// call this once at the startup of your application
11+
configure({
12+
clientId: "<YOUR_CLIENT_ID>",
13+
});
14+
```
15+
16+
## Example Usage
17+
18+
```ts
19+
import { getV1Events } from "@thirdweb-dev/insight";
20+
21+
const events = await getV1Events({
22+
query: {
23+
chain: [1, 137],
24+
filter_address: "0x1234567890123456789012345678901234567890",
25+
},
26+
});
27+
```
28+
29+
This package was autogenerated from the [Insight openAPI spec](https://insight-api.thirdweb.com/reference) using [@hey-api/openapi-ts](https://github.com/hey-api/openapi-ts)

packages/insight/biome.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.2/schema.json",
3+
"extends": ["../../biome.json"],
4+
"files": {
5+
"ignore": ["src/client/**"]
6+
}
7+
}

packages/insight/openapi-ts.config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from "@hey-api/openapi-ts";
2+
3+
export default defineConfig({
4+
input: "https://insight.thirdweb.com/openapi.json",
5+
output: { path: "src/client" },
6+
plugins: ["@hey-api/client-fetch"],
7+
});

packages/insight/package.json

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "@thirdweb-dev/insight",
3+
"version": "0.0.1",
4+
"repository": {
5+
"type": "git",
6+
"url": "git+https://github.com/thirdweb-dev/js.git#main"
7+
},
8+
"license": "Apache-2.0",
9+
"bugs": {
10+
"url": "https://github.com/thirdweb-dev/js/issues"
11+
},
12+
"author": "thirdweb eng <[email protected]>",
13+
"type": "module",
14+
"main": "./dist/cjs/exports/thirdweb.js",
15+
"module": "./dist/esm/exports/thirdweb.js",
16+
"types": "./dist/types/exports/thirdweb.d.ts",
17+
"typings": "./dist/types/exports/thirdweb.d.ts",
18+
"exports": {
19+
".": {
20+
"types": "./dist/types/exports/thirdweb.d.ts",
21+
"import": "./dist/esm/exports/thirdweb.js",
22+
"default": "./dist/cjs/exports/thirdweb.js"
23+
},
24+
"./package.json": "./package.json"
25+
},
26+
"files": ["dist/*", "src/*"],
27+
"dependencies": {
28+
"@hey-api/client-fetch": "0.10.0",
29+
"tslib": "^2.8.1"
30+
},
31+
"devDependencies": {
32+
"@hey-api/openapi-ts": "0.66.1",
33+
"rimraf": "6.0.1"
34+
},
35+
"peerDependencies": {
36+
"typescript": ">=5.0.4"
37+
},
38+
"peerDependenciesMeta": {
39+
"typescript": {
40+
"optional": true
41+
}
42+
},
43+
"scripts": {
44+
"format": "biome format ./src --write",
45+
"lint": "biome check ./src",
46+
"fix": "biome check ./src --fix",
47+
"build": "pnpm clean && pnpm build:cjs && pnpm build:esm && pnpm build:types",
48+
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/cjs --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json",
49+
"build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./dist/esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/esm/package.json",
50+
"build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
51+
"clean": "rimraf dist",
52+
"build:generate": "openapi-ts && pnpm format"
53+
},
54+
"engines": {
55+
"node": ">=18"
56+
}
57+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import {
4+
type Config,
5+
type ClientOptions as DefaultClientOptions,
6+
createClient,
7+
createConfig,
8+
} from "@hey-api/client-fetch";
9+
import type { ClientOptions } from "./types.gen.js";
10+
11+
/**
12+
* The `createClientConfig()` function will be called on client initialization
13+
* and the returned object will become the client's initial configuration.
14+
*
15+
* You may want to initialize your client this way instead of calling
16+
* `setConfig()`. This is useful for example if you're using Next.js
17+
* to ensure your client always has the correct values.
18+
*/
19+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> =
20+
(
21+
override?: Config<DefaultClientOptions & T>,
22+
) => Config<Required<DefaultClientOptions> & T>;
23+
24+
export const client = createClient(createConfig<ClientOptions>());

packages/insight/src/client/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
export * from "./types.gen.js";
3+
export * from "./sdk.gen.js";

0 commit comments

Comments
 (0)