Skip to content

chore: coinbase and moonpay integration #651

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

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
020ff1f
chore: coinbase and moonpay integration
turnekybc May 30, 2025
fd88a42
chore: update uniswap/core imports
turnekybc May 30, 2025
76530eb
chore: add debug
turnekybc May 30, 2025
c502853
chore: fiat on ramp
turnekybc Jun 1, 2025
db4969b
chore: create onramp component
turnekybc Jun 2, 2025
8c5aa69
chore: update signature
turnekybc Jun 2, 2025
153e44d
chore: gen code
turnekybc Jun 2, 2025
64ea741
chore: integrate with OnchainKit hooks and MoonPay widget
turnekybc Jun 6, 2025
10a7a39
chore: prettier
turnekybc Jun 7, 2025
b3d23c8
chore: codegen
turnekybc Jun 7, 2025
47efba0
chore: codegen
turnekybc Jun 8, 2025
0c2f2c1
chore: codegen
turnekybc Jun 8, 2025
64403c8
chore: codegen
turnekybc Jun 8, 2025
d8e6df5
chore: codegen
turnekybc Jun 8, 2025
bf00dea
chore: codegen
turnekybc Jun 9, 2025
f177400
chore: codegen
turnekybc Jun 10, 2025
c2330b1
chore: prettier
turnekybc Jun 10, 2025
9c7230c
chore: codegen
turnekybc Jun 10, 2025
f66d36d
chore: codegen
turnekybc Jun 11, 2025
01d9a48
chore: codegen
turnekybc Jun 12, 2025
1f1252d
chore: codegen
turnekybc Jun 12, 2025
b04a4be
chore: codegen
turnekybc Jun 13, 2025
b11f4db
chore: codegen
turnekybc Jun 18, 2025
fae5298
chore: codegen
turnekybc Jun 24, 2025
c4d134c
chore: codegen
turnekybc Jun 25, 2025
47f3874
chore: update onramp
turnekybc Jun 27, 2025
7aa38bf
chore: codegen
turnekybc Jun 27, 2025
929aa83
chore: codegen
turnekybc Jun 27, 2025
5f76e20
chore: prettier
turnekybc Jun 28, 2025
6087c17
codegen
turnekybc Jul 8, 2025
1f31621
codegen
turnekybc Jul 8, 2025
9fa66b2
update pnpm-lock.yaml
turnekybc Jul 8, 2025
333f6d9
clean up on-ramp component
turnekybc Jul 8, 2025
f6a71b5
funding container
moe-dev Jul 8, 2025
85b622f
buy buttons with popups
moe-dev Jul 8, 2025
1de53ba
pass eth address to onRamp component
moe-dev Jul 8, 2025
1e434ec
enable sandbox mode
turnekybc Jul 9, 2025
a2121fb
update codegen
turnekybc Jul 9, 2025
0217319
updated example
moe-dev Jul 10, 2025
be1ff5a
use sandboxMode
turnekybc Jul 11, 2025
948d757
add sandboxMode
turnekybc Jul 11, 2025
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
3,508 changes: 3,508 additions & 0 deletions .github/workflows/Untitled-1.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion examples/react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@coinbase/onchainkit": "^0.38.13",
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@hello-pangea/dnd": "^17.0.0",
"@moonpay/moonpay-js": "^0.7.0",
"@moonpay/moonpay-react": "^1.10.1",
"@mui/icons-material": "^6.1.5",
"@mui/material": "^6.1.5",
"@noble/hashes": "1.4.0",
Expand Down Expand Up @@ -41,6 +44,7 @@
"react-international-phone": "^4.3.0",
"sonner": "^1.4.41",
"tweetnacl": "^1.0.3",
"typescript": "5.4.3"
"typescript": "5.4.3",
"viem": "^2.30.5"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";

import React from "react";
import { OnchainKitProvider } from "@coinbase/onchainkit";
import { sepolia } from "viem/chains";

interface CoinbaseCryptoProviderProps {
children: React.ReactNode;
}

const CoinbaseCryptoProvider = ({ children }: CoinbaseCryptoProviderProps) => {
return (
<OnchainKitProvider
apiKey={process.env.NEXT_PUBLIC_ONCHAINKIT_API_KEY!}
projectId={process.env.NEXT_PUBLIC_CDP_PROJECT_ID!}
chain={sepolia}
>
{children}
</OnchainKitProvider>
);
};

export default CoinbaseCryptoProvider;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import dynamic from "next/dynamic";

const MoonPayProvider = dynamic(
() => import("@moonpay/moonpay-react").then((mod) => mod.MoonPayProvider),
{ ssr: false },
);

interface MoonPayCryptoProviderProps {
children: React.ReactNode;
}

const MoonPayCryptoProvider = ({ children }: MoonPayCryptoProviderProps) => {
return (
<MoonPayProvider
apiKey={process.env.NEXT_PUBLIC_MOONPAY_API_KEY!}
debug={true}
>
{children}
</MoonPayProvider>
);
};

export default MoonPayCryptoProvider;
139 changes: 139 additions & 0 deletions examples/react-components/src/app/dashboard/OnRamp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { useState } from "react";
import { useTurnkey } from "@turnkey/sdk-react";
import { Box, Modal, Typography } from "@mui/material";

interface OnRampProps {
ethAddress: string;
}

export const OnRamp = ({ ethAddress }: OnRampProps) => {
const { turnkey, indexedDbClient } = useTurnkey();
const [isSignModalOpen, setSignModalOpen] = useState(false);

const handleModalOpen = () => setSignModalOpen(true);
const handleModalClose = () => setSignModalOpen(false);

const generateCoinbaseUrl = async () => {
try {
const session = await turnkey?.getSession();

const response = await indexedDbClient?.initFiatOnRamp({
organizationId: session?.organizationId!,
onrampProvider: "FIAT_ON_RAMP_PROVIDER_COINBASE",
walletAddress: ethAddress,
network: "FIAT_ON_RAMP_BLOCKCHAIN_NETWORK_ETHEREUM",
cryptoCurrencyCode: "FIAT_ON_RAMP_CRYPTO_CURRENCY_ETH",
fiatCurrencyCode: "FIAT_ON_RAMP_CURRENCY_USD",
countryCode: "US",
countrySubdivisionCode: "ME",
sandboxMode: true,
});

if (response?.onRampUrl) {
window.open(
response.onRampUrl,
"_blank",
"popup,width=500,height=700,scrollbars=yes,resizable=yes",
);
}
} catch (error) {
console.error("Failed to init Coinbase on-ramp:", error);
}
};

const generateMoonPayUrl = async () => {
try {
const session = await turnkey?.getSession();

const response = await indexedDbClient?.initFiatOnRamp({
organizationId: session?.organizationId!,
onrampProvider: "FIAT_ON_RAMP_PROVIDER_MOONPAY",
walletAddress: ethAddress,
network: "FIAT_ON_RAMP_BLOCKCHAIN_NETWORK_ETHEREUM",
cryptoCurrencyCode: "FIAT_ON_RAMP_CRYPTO_CURRENCY_ETH",
fiatCurrencyCode: "FIAT_ON_RAMP_CURRENCY_USD",
sandboxMode: true,
});

if (response?.onRampUrl) {
window.open(
response.onRampUrl,
"_blank",
"popup,width=500,height=700,scrollbars=yes,resizable=yes",
);
}
} catch (error) {
console.error("Failed to init MoonPay on-ramp:", error);
}
};

return (
<>
<button className="whiteButton" onClick={handleModalOpen}>
<svg
xmlns="http://www.w3.org/2000/svg"
width="25"
height="24"
viewBox="0 0 25 24"
fill="none"
>
<path
d="M11.5 13H5.5V11H11.5V5H13.5V11H19.5V13H13.5V19H11.5V13Z"
fill="#878C94"
/>
</svg>
Add Funds
</button>

<Modal open={isSignModalOpen} onClose={handleModalClose}>
<Box
sx={{
outline: "none",
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: 400,
bgcolor: "var(--Greyscale-20, #f5f7fb)",
boxShadow: 24,
p: 4,
borderRadius: 2,
}}
>
<div
onClick={handleModalClose}
style={{
position: "absolute",
top: "16px",
right: "16px",
background: "none",
border: "none",
fontSize: "20px",
fontWeight: "bold",
cursor: "pointer",
color: "#6C727E",
}}
>
&times;
</div>
<Typography variant="h6" className="modalTitle">
Add Funds to your wallet
</Typography>
<Typography variant="subtitle2" sx={{ color: "#6C727E", mb: 2 }}>
Your crypto will be deposited directly into your Turnkey wallet
</Typography>
<div className="purchaseButtons">
<button className="whiteButton" onClick={generateMoonPayUrl}>
<img src="/images/moonpay.jpg" alt="MoonPay" />
Buy with MoonPay
</button>
<button className="whiteButton" onClick={generateCoinbaseUrl}>
<img src="/images/coinbase.png" alt="Coinbase" />
Buy with Coinbase
</button>
</div>
</Box>
</Modal>
</>
);
};
47 changes: 46 additions & 1 deletion examples/react-components/src/app/dashboard/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ body {
padding: 8px 24px;
border-radius: 8px;
width: 542px;
height: 584px;
height: 642px;
border: 1px solid var(--Greyscale-100, #ebedf2);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
display: flex;
Expand Down Expand Up @@ -215,6 +215,12 @@ body {
margin-bottom: 12px;
/* margin-top: 24px; */
}

.signMessage {
margin-bottom: 12px;
/* margin-top: 24px; */
}

.exportImportGroup {
margin-top: 12px;
display: flex;
Expand Down Expand Up @@ -465,3 +471,42 @@ button:hover {
.sonner-toaster > div {
pointer-events: auto;
}

.purchaseButtons {
display: flex;
flex-direction: column;
gap: 12px;
}

.whiteButton {
letter-spacing: -0.01em;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10px 16px;
gap: 8px;
color: var(--button-text);
width: 100%;
font-size: 1rem;
background: var(--button-bg);
border: 1px solid var(--button-border);
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease;
}

.whiteButton img {
width: 24px;
height: 24px;
object-fit: contain;
}
.whiteButton:hover {
background-color: var(--button-hover-bg);
}

.whiteButton:disabled {
color: var(--button-disabled-text);
background: var(--button-disabled-bg);
border-color: var(--button-disabled-border);
cursor: default;
}
10 changes: 10 additions & 0 deletions examples/react-components/src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ import Navbar from "../components/Navbar";
import { Toaster, toast } from "sonner";
import { jwtDecode } from "jwt-decode";
import { useSessionExpiry } from "../providers/SessionExpiryProvider";
import { MoonPayBuyWidget } from "@moonpay/moonpay-react";
import { loadMoonPay } from "@moonpay/moonpay-js";
import crypto from "crypto";

import { OnRamp } from "./OnRamp";

export default function Dashboard() {
const router = useRouter();
Expand Down Expand Up @@ -471,6 +476,9 @@ export default function Dashboard() {
: "Verification failed.",
);
};
const ethAddress = accounts.find((account: any) =>
account.address.startsWith("0x"),
)?.address;
if (loading) {
return (
<main className="main">
Expand Down Expand Up @@ -711,6 +719,7 @@ export default function Dashboard() {
Sign a message
</button>
</div>
<OnRamp ethAddress={ethAddress || ""} />
</RadioGroup>

<div className="exportImportGroup">
Expand All @@ -724,6 +733,7 @@ export default function Dashboard() {
onHandleImportSuccess={handleImportSuccess}
/>
</div>

<div className="authFooter">
<div className="authFooterLeft">
<div onClick={handleLogout} className="authFooterButton">
Expand Down
6 changes: 5 additions & 1 deletion examples/react-components/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "@turnkey/sdk-react/styles";
import { TurnkeyProvider, TurnkeyThemeProvider } from "@turnkey/sdk-react";
import { EthereumWallet } from "@turnkey/wallet-stamper";
import { SessionExpiryProvider } from "./providers/SessionExpiryProvider";
import CoinbaseCryptoProvider from "./components/CoinbaseCryptoProvider";
import MoonPayCryptoProvider from "./components/MoonPayCryptoProvider";
const wallet = new EthereumWallet();
const turnkeyConfig = {
apiBaseUrl: process.env.NEXT_PUBLIC_BASE_URL!,
Expand All @@ -27,7 +29,9 @@ function RootLayout({ children }: RootLayoutProps) {
<body>
<TurnkeyProvider config={turnkeyConfig}>
<SessionExpiryProvider warningBeforeSec={30}>
{children}
<CoinbaseCryptoProvider>
<MoonPayCryptoProvider>{children}</MoonPayCryptoProvider>
</CoinbaseCryptoProvider>
</SessionExpiryProvider>
</TurnkeyProvider>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/react-components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand Down
Loading
Loading