Skip to content

Commit 185d2f3

Browse files
[SDK] Add Insight API client (#6706)
1 parent e8fb417 commit 185d2f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6861
-239
lines changed

.changeset/quick-bugs-remain.md

Lines changed: 31 additions & 0 deletions
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

Lines changed: 45 additions & 0 deletions
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

Lines changed: 15 additions & 5 deletions
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

Lines changed: 6 additions & 31 deletions
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

Lines changed: 0 additions & 3 deletions
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/playground-web/src/lib/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ setThirdwebDomains({
99
bundler: process.env.NEXT_PUBLIC_BUNDLER_URL,
1010
pay: process.env.NEXT_PUBLIC_PAY_URL,
1111
analytics: process.env.NEXT_PUBLIC_ANALYTICS_URL,
12+
insight: process.env.NEXT_PUBLIC_INSIGHT_URL,
1213
});
1314

1415
const isDev =

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 29 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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+
}
Lines changed: 7 additions & 0 deletions
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+
});

0 commit comments

Comments
 (0)