In this guide, we’ll explore how to leverage the WalletClient
in the Turnkey SDK to authenticate requests to Turnkey’s API using either Solana or Ethereum wallets.
apiBaseUrl
: The base URL of the Turnkey API: https://api.turnkey.com
.defaultOrganizationId
: Your parent organization ID, which you can find in the Turnkey dashboard.wallet
: The wallet interface used to sign requests. In this example, we’ll use the EthereumWallet
interface.TurnkeyProvider
in your app/layout.tsx
file:app/page.tsx
where we’ll implement the wallet authentication functionality:@turnkey/sdk-server
package. This setup enables you to authenticate requests to Turnkey’s API using the parent organization’s public/private API key pair. This is required to create new sub-organizations on behalf of a user.
"use server"
directive at the top of the file where you’re initializing the Turnkey server client. This will ensure that the function is executed on the server-side and will have access to the server-side environment variables e.g. your parent organization’s public/private API key pair. For more information on Next.js server actions, see the Next.js documentation on Server Actions and Mutations.getPublicKey
method on the WalletClient
instance which will retrieve the public key from the user’s wallet.
app/page.tsx
file we created earlier importing the getSubOrg
function we defined in our server action.createSubOrg
to create a sub-organization for new user sign-ups.createSubOrg
function within the login method. The curve type is set to API_KEY_CURVE_SECP256K1
since we’re using an Ethereum wallet in this example.login
method on the WalletClient
instance. This will save a read-only session token to the localStorage
to authenticate future read requests.
getWallets
method on the WalletClient
instance.
loginWithReadWriteSession
method on the WalletClient
instance. This will save a read-write session token to the localStorage
to authenticate future read/write requests. This session can be used with the TurnkeyIframeClient
to make read/write requests to the Turnkey API.
login
with loginWithReadWriteSession
and use the getActiveClient
method to get the IframeClient
instance and using it to create a new wallet.addWallet
which will create a new wallet using the read-write client. We’ll also add a button to trigger this function.