Skip to content

[Playground] Add Engine user transactions example to playground #7470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/playground-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@radix-ui/react-switch": "^1.2.5",
"@radix-ui/react-tooltip": "1.2.7",
"@tanstack/react-query": "5.81.5",
"@thirdweb-dev/engine": "workspace:*",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"date-fns": "4.1.0",
Expand Down
97 changes: 97 additions & 0 deletions apps/playground-web/src/app/engine/users/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import type { Metadata } from "next";
import { GatewayPreview } from "@/components/account-abstraction/gateway";
import { PageLayout } from "@/components/blocks/APIHeader";
import { CodeExample } from "@/components/code/code-example";
import ThirdwebProvider from "@/components/thirdweb-provider";
import { metadataBase } from "@/lib/constants";

export const metadata: Metadata = {
description: "Transactions from user wallets with monitoring and retries",
metadataBase,
title: "User Transactions | thirdweb",
};

export default function Page() {
return (
<ThirdwebProvider>
<PageLayout
description={
<>Transactions from user wallets with monitoring and retries.</>
}
docsLink="https://portal.thirdweb.com/engine?utm_source=playground"
title="User Transactions"
>
<UserTransactions />
</PageLayout>
</ThirdwebProvider>
);
}

function UserTransactions() {
return (
<>
<CodeExample
code={`\
import { inAppWallet } from "thirdweb/wallets/in-app";
import { ConnectButton, useActiveAccount } from "thirdweb/react";

const wallet = inAppWallet();

function App() {
const activeWallet = useActiveWallet();

const handleClick = async () => {
const walletAddress = activeWallet?.getAccount()?.address;
// transactions are a simple POST request to the engine API
// or use the @thirdweb-dev/engine type-safe JS SDK
const response = await fetch(
"https://api.thirdweb.com/v1/contract/write",
{
method: "POST",
headers: {
"Content-Type": "application/json",
"x-client-id": "<your-project-client-id>",
// uses the in-app wallet's auth token to authenticate the request
"Authorization": "Bearer " + activeWallet?.getAuthToken?.(),
},
body: JSON.stringify({
chainId: "84532",
calls: [
{
contractAddress: "0x...",
method: "function claim(address to, uint256 amount)",
params: [walletAddress, "1"],
},
],
}),
});
};

return (
<>
<ConnectButton
client={client}
wallet={[wallet]}
connectButton={{
label: "Login to mint!",
}}
/>
<Button
onClick={handleClick}
>
Mint
</Button>
</>
);
}`}
header={{
description:
"Engine can queue, monitor, and retry transactions from your users in-app wallets. All transactions and analytics will be displayed in your developer dashboard.",
title: "Transactions from User Wallets",
}}
lang="tsx"
preview={<GatewayPreview />}
/>
</>
);
}
4 changes: 4 additions & 0 deletions apps/playground-web/src/app/navLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const engineSidebarLinks: SidebarLink = {
expanded: false,
isCollapsible: false,
links: [
{
href: "/engine/users",
name: "From User Wallets",
},
{
href: "/engine/airdrop",
name: "Airdrop",
Expand Down
Loading
Loading