Getting Started with Turnkey
Let's get started with a basic example using Turnkey
Pre-requisites
1. Create a delegate user on the Turnkey dashboard
2. Creating users and sub-organizations
Adding a delegate user
import { useTurnkey, AuthState } from '@turnkey/react-wallet-kit';
...
const LoginComponent = () => {
const { authState, user, wallets, createWallet, refreshWallets, httpClient } = useTurnkey();
...
const delegateApiKeyName = process.env.NEXT_PUBLIC_ENCLAVE_DELEGATE_API_KEY_NAME!;
const delegatePublicKey = process.env.NEXT_PUBLIC_ENCLAVE_DELEGATE_PUBLIC_KEY!;
if (!delegateApiKeyName || !delegatePublicKey) {
console.log('⚠️ Delegate API credentials not found in environment variables, skipping');
return;
}
console.log('📝 Adding delegate user to sub-organization...');
const curveType: "API_KEY_CURVE_P256" = "API_KEY_CURVE_P256";
const delegateApiKeys = [{
apiKeyName: delegateApiKeyName,
publicKey: delegatePublicKey,
curveType,
}];
const fetchQuote = async () => {
// Get the current organization info
const orgInfo = await httpClient.getOrganization();
const subOrgId = orgInfo?.organizationData?.organizationId;
const response = await httpClient.createUsers({
organizationId: subOrgId,
users: [
{
userName: "enclave_delegate_user",
userEmail: "[email protected]",
userTags: [],
apiKeys: delegateApiKeys,
authenticators: [],
oauthProviders: [],
}
]
});
}
}
Adding a new end-user wallet
Fetching a quoteLast updated