|
| 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 | +} |
0 commit comments