Skip to content

Commit acbbf20

Browse files
[Playground] Add Engine user transactions example to playground (#7470)
1 parent 4375e73 commit acbbf20

File tree

7 files changed

+542
-113
lines changed

7 files changed

+542
-113
lines changed

.changeset/odd-rockets-sink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/api": patch
3+
---
4+
5+
Update to latest API

apps/playground-web/src/app/data/pages-metadata.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ export const headlessComponentsFeatureCards: FeatureCardMetadata[] = [
106106
];
107107

108108
export const transactionsFeatureCards: FeatureCardMetadata[] = [
109+
{
110+
icon: UserIcon,
111+
title: "From User Wallets",
112+
link: "/transactions/users",
113+
description: "Transactions from user wallets with monitoring and retries.",
114+
},
109115
{
110116
icon: PlaneIcon,
111117
title: "Airdrop Tokens",

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

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

0 commit comments

Comments
 (0)