Skip to content

Commit 884fba3

Browse files
Add Engine user transactions example to playground
1 parent adfa56b commit 884fba3

File tree

6 files changed

+484
-112
lines changed

6 files changed

+484
-112
lines changed

apps/playground-web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"@radix-ui/react-switch": "^1.2.5",
1414
"@radix-ui/react-tooltip": "1.2.7",
1515
"@tanstack/react-query": "5.81.5",
16+
"@thirdweb-dev/engine": "workspace:*",
1617
"class-variance-authority": "^0.7.1",
1718
"clsx": "^2.1.1",
1819
"date-fns": "4.1.0",
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import type { Metadata } from "next";
2+
import { GatewayPreview } from "@/components/account-abstraction/gateway";
3+
import { PageLayout } from "@/components/blocks/APIHeader";
4+
import { CodeExample } from "@/components/code/code-example";
5+
import ThirdwebProvider from "@/components/thirdweb-provider";
6+
import { metadataBase } from "@/lib/constants";
7+
8+
export const metadata: Metadata = {
9+
description: "Transactions from user wallets with monitoring and retries",
10+
metadataBase,
11+
title: "User Transactions | thirdweb",
12+
};
13+
14+
export default function Page() {
15+
return (
16+
<ThirdwebProvider>
17+
<PageLayout
18+
description={
19+
<>Transactions from user wallets with monitoring and retries.</>
20+
}
21+
docsLink="https://portal.thirdweb.com/engine?utm_source=playground"
22+
title="User Transactions"
23+
>
24+
<UserTransactions />
25+
</PageLayout>
26+
</ThirdwebProvider>
27+
);
28+
}
29+
30+
function UserTransactions() {
31+
return (
32+
<>
33+
<CodeExample
34+
code={`\
35+
import { inAppWallet } from "thirdweb/wallets/in-app";
36+
import { ConnectButton, useActiveAccount } from "thirdweb/react";
37+
38+
const wallet = inAppWallet();
39+
40+
function App() {
41+
const activeWallet = useActiveWallet();
42+
43+
const handleClick = async () => {
44+
const walletAddress = activeWallet?.getAccount()?.address;
45+
// transactions are a simple POST request to the engine API
46+
// or use the @thirdweb-dev/engine type-safe JS SDK
47+
const response = await fetch(
48+
"https://api.thirdweb.com/v1/contract/write",
49+
{
50+
method: "POST",
51+
headers: {
52+
"Content-Type": "application/json",
53+
"x-client-id": "<your-project-client-id>",
54+
// uses the in-app wallet's auth token to authenticate the request
55+
"Authorization": "Bearer " + activeWallet?.getAuthToken?.(),
56+
},
57+
body: JSON.stringify({
58+
chainId: "84532",
59+
calls: [
60+
{
61+
contractAddress: "0x...",
62+
method: "function claim(address to, uint256 amount)",
63+
params: [walletAddress, "1"],
64+
},
65+
],
66+
}),
67+
});
68+
};
69+
70+
return (
71+
<>
72+
<ConnectButton
73+
client={client}
74+
wallet={[wallet]}
75+
connectButton={{
76+
label: "Login to mint!",
77+
}}
78+
/>
79+
<Button
80+
onClick={handleClick}
81+
>
82+
Mint
83+
</Button>
84+
</>
85+
);
86+
}`}
87+
header={{
88+
description:
89+
"Engine can queue, monitor, and retry transactions from your users in-app wallets. All transactions and analytics will be displayed in your developer dashboard.",
90+
title: "Transactions from User Wallets",
91+
}}
92+
lang="tsx"
93+
preview={<GatewayPreview />}
94+
/>
95+
</>
96+
);
97+
}

apps/playground-web/src/app/navLinks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ const engineSidebarLinks: SidebarLink = {
116116
expanded: false,
117117
isCollapsible: false,
118118
links: [
119+
{
120+
href: "/engine/users",
121+
name: "From User Wallets",
122+
},
119123
{
120124
href: "/engine/airdrop",
121125
name: "Airdrop",

0 commit comments

Comments
 (0)