Turnkey SDK

Overview

The Turnkey SDK includes functionality to interact with Turnkey in various contexts and ecosystems. It consists of three main NPM package groups.

The diagram below helps visualize the packages in our SDK organized by the functionality they expose.

Primary Turnkey Web SDK Packages

The following packages expose the main functionality required to build Turnkey-powered applications. Each package exposes functions, and/or client classes with methods that manage the process of authenticating requests to the Turnkey API in the contexts of a generic browser environment or react client environment, or a server environment.

While these higher level packages are the main points of reference to be used while designing and building Turnkey applications, they wrap other packages with lower level functionality which we also expose separately for those who would like to explore them for more specialized use cases. These packages are listed and described below in the Advanced Functionality SDK Packages section.

Our main web SDK packages are as follows:

PackageDescriptionNPMChangelogDocs
@turnkey/sdk-browserThe @turnkey/sdk-browser package exposes functionality that lets developers build browser based applications that interact with the Turnkey API with different types of authentication. It consists of different clients that enable requests to the API to be authenticated via different auth methods like user sessions, passkeys and iFrames. It also contains methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests.changelogDocs
@turnkey/sdk-serverThe @turnkey/sdk-server package exposes functionality that lets developers build server-side functionality for applications that interact with the Turnkey API with different types of authentication – allowing applications to authenticate users, manage sessions, and perform organizational operations securely and efficiently. It consists of an API Client and API Proxies that enable requests to the Turnkey API to be authenticated with the appropriate credentials. Specifically, the API Client manages requests signed by the user’s authentication details, and the API proxies handle requests signed by the parent organization’s authentication details. Use this package to handle server-side interactions for applications that interact with the Turnkey API.changelogDocs
@turnkey/sdk-reactThe @turnkey/sdk-react package wraps the functionality from the @turnkey/sdk-browser package to allow developers to build react based applications that interact with the Turnkey API with different types of authentication. It allows developers to use the same clients exposed in @turnkey/sdk-browser that enable requests to the API to be authenticated via different auth methods like user sessions, passkey and iFrames. It also contains the same methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests. Use this package when you’re building React-based frontend applications that interact with the Turnkey API.changelogDocs

The diagram below helps visualize how each package can be used to devlop the appropriate service in your Turnkey Powered Application, and how Turnkey requests would flow between those services.

Chain/Ecosystem-Specific Signing SDK Packages

The following packages contain chain or ecosystem specific signers that take some of our Primary Turnkey Web SDK Packages (usually @turnkey/sdk-browser or @turnkey/sdk-server) and add additional support based on the signing process or transaction structure relevant to that specific chain or ecosystem.

PackageNPMDescriptionChangelog
@turnkey/ethersTurnkey Signer for Etherschangelog
@turnkey/viemTurnkey Signer for Viemchangelog
@turnkey/cosmjsTurnkey Signer for CosmJSchangelog
@turnkey/solanaTurnkey Signer for Solanachangelog
@turnkey/eip-1193-providerTurnkey-compatible EIP-1193 Providerchangelog

Advanced Functionality SDK Packages

For those with more specialized use cases, Turnkey exposes it’s lower level-libraries stamping and encryption libraries to be used directly. Note: for most use-cases, these libraries are not meant to be used directly and we encourage working on designing your application mainlyusing our Primary Turnkey Web SDK Packages along with our Chain and Ecosystem Specific SDK Packages as per your use case!

Request Stamping

PackageNPMDescriptionChangelogDocs
@turnkey/httpLower-level, fully typed HTTP client for interacting with Turnkey APIchangelogDocs
@turnkey/api-key-stamperProvide API key signatures over Turnkey requestschangelogDocs
@turnkey/iframe-stamperProvide API key signatures over Turnkey requests within iframe contextschangelogDocs
@turnkey/webauthn-stamperProvide Webauthn signatures over Turnkey requestschangelogDocs
@turnkey/wallet-stamperProvide wallet signatures over Turnkey requestschangelogDocs
@turnkey/sdk-react-native-passkey-stamperProvide Passkey signatures over Turnkey requests in a React Native contextchangelogDocs

Utilities

PackageNPMDescriptionChangelog
@turnkey/encodingEncoding and decoding utilities, primarily for internal usagechangelog
@turnkey/cryptoCryptographic utilities for P256 keys, encryption, and decryptionchangelog

Code Examples

Instant examples (powered by Stackblitz)

The following code examples have been loaded into Stackblitz web environments so you can test them out immediately

ExampleDescriptionStackblitz Link
email-auth-local-storageA NextJS app demonstrating a complete email auth flow using a locally stored target embedded keyTest it out on Stackblitz!
with-eth-passkey-signersA NextJS app powering users to create suborgs and sign messages via Viem or EthersTest it out on Stackblitz!
with-solanaCreate a new Solana address, then sign and broadcast a transaction on Solana’s devnetTest it out on Stackblitz!
with-solana-passkeysA NextJS app powering users to create suborgs, sign messages, and create transactions sponsored by the parent org using @turnkey/solanaTest it out on Stackblitz!

Other Code Examples

The below examples will require a local installation of node.js. Follow the specific instructions in the respective readme’s of each examples to run them!

ExampleDescription
demo-consumer-walletA minimal consumer wallet app powered by Turnkey and WalletConnect
demo-passkey-walletA minimal consumer wallet app powered by Turnkey and passkeys
demo-ethers-passkeysA NextJS app that demonstrates how to use @turnkey/ethers to build a passkey-powered application
demo-viem-passkeysA NextJS app that demonstrates how to use @turnkey/viem to build a passkey-powered application
react-native-demo-walletA React Native app that demonstrates how to use the Turnkey’s JavaScript packages in a mobile environment to authenticate users, create wallets, export wallets, sign messages, and more
flutter-demo-appA Flutter app that demonstrates how to use the Turnkey’s Flutter packages to authenticate users, create wallets, export wallets, sign messages, and more
deployerCompile and deploy a smart contract
email-authA NextJS app demonstrating a complete email auth flow using Turnkey iframes
wallet-import-exportA NextJS app demonstrating complete wallet import and export flows
rebalancerA demo application which showcases an example of how to use Turnkey for managing multiple types of keys & users
sweeperSweep funds from one address to a different address
trading-runnerA sample application demonstrating a trading operation, using various private keys, users, and policies, powered by Uniswap
with-ethersCreate a new Ethereum address, then sign and broadcast a transaction using the Ethers signer with Infura
with-viemSign and broadcast a transaction using the Turnkey Custom Account and Infura
with-cosmjsCreate a new Cosmos address, then sign and broadcast a transaction on Celestia testnet using the CosmJS signer
with-bitcoinCreate a new wallet, derive a BTC address, create, sign, and broadcast a transaction using BitcoinJS and other external APIs
with-biconomy-aaCreate a new wallet, connect a Turnkey wallet client to Biconomy Nexus, and create, sign, and broadcast an EIP-1559 transaction
with-zerodev-aaCreate a new wallet, instantiate a Turnkey signer, create a ZeroDev kernel account and client, and broadcast a UserOp
with-gnosisCreate new Ethereum addresses, configure a 3/3 Gnosis safe, and create + execute a transaction from it
with-uniswapSign and broadcast a Uniswap v3 trade using the Ethers signer with Infura
with-nonce-managerCreate a new Ethereum address, then sign and broadcast multiple transactions in a sequential or optimistic manner
with-offlineSign a Turnkey request in offline context
with-federated-passkeysA NextJS app that demonstrates how to use Turnkey to build a federated, webauthn powered authentication flow
with-eip-1193-providerA NextJS app that demonstrates how to use Turnkey the @turnkey/eip-1193-provider in your app
with-wallet-stamperA NextJS app that demonstrates how to use Turnkey the @turnkey/wallet-stamper in your app

Demos built with Turnkey

Demo Consumer Wallet (code)

A minimal consumer wallet app powered by Turnkey. Behind the scenes, it uses @turnkey/ethers for signing and WalletConnect (v1) for accessing dapps.

https://github.com/tkhq/demo-consumer-wallet/assets/127255904/2c3409df-2d7c-4ec3-9aa8-e2944a0b0e0a

See https://github.com/tkhq/demo-consumer-wallet for the code.

A wallet application showing how users can register and authenticate using passkeys. This demo uses the Turnkey API to create a new Turnkey Sub-Organization for each user, create a testnet Ethereum address and send a transaction on Sepolia (ETH testnet).

See https://wallet.tx.xyz (and https://github.com/tkhq/demo-passkey-wallet for the code).

Demo Ethers Passkeys (code)

A simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/ethers signer, using passkeys.

See https://github.com/tkhq/demo-ethers-passkeys for the code.

Demo Viem Passkeys (code)

A similar, simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/viem signer, using passkeys.

See https://github.com/tkhq/demo-viem-passkeys for the code.

React Native Demo App (code)

A React Native app that demonstrates how to use the Turnkey’s JavaScript packages in a mobile environment to authenticate users, create wallets, export wallets, sign messages, and more

https://github.com/user-attachments/assets/e4cff012-11e9-4636-b67a-5dbf75355832

See https://github.com/tkhq/react-native-demo-wallet for the code.

Flutter Demo App (code)

A Flutter app that demonstrates how to use the Turnkey’s Flutter packages to authenticate users, create wallets, export wallets, sign messages, and more

https://github.com/user-attachments/assets/3d583ed8-1eff-4101-ae43-3c76c655e635

See https://github.com/tkhq/dart-sdk/tree/main/examples/flutter-demo-app for the code

Turnkey SDK

Overview

The Turnkey SDK includes functionality to interact with Turnkey in various contexts and ecosystems. It consists of three main NPM package groups.

The diagram below helps visualize the packages in our SDK organized by the functionality they expose.

Primary Turnkey Web SDK Packages

The following packages expose the main functionality required to build Turnkey-powered applications. Each package exposes functions, and/or client classes with methods that manage the process of authenticating requests to the Turnkey API in the contexts of a generic browser environment or react client environment, or a server environment.

While these higher level packages are the main points of reference to be used while designing and building Turnkey applications, they wrap other packages with lower level functionality which we also expose separately for those who would like to explore them for more specialized use cases. These packages are listed and described below in the Advanced Functionality SDK Packages section.

Our main web SDK packages are as follows:

PackageDescriptionNPMChangelogDocs
@turnkey/sdk-browserThe @turnkey/sdk-browser package exposes functionality that lets developers build browser based applications that interact with the Turnkey API with different types of authentication. It consists of different clients that enable requests to the API to be authenticated via different auth methods like user sessions, passkeys and iFrames. It also contains methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests.changelogDocs
@turnkey/sdk-serverThe @turnkey/sdk-server package exposes functionality that lets developers build server-side functionality for applications that interact with the Turnkey API with different types of authentication – allowing applications to authenticate users, manage sessions, and perform organizational operations securely and efficiently. It consists of an API Client and API Proxies that enable requests to the Turnkey API to be authenticated with the appropriate credentials. Specifically, the API Client manages requests signed by the user’s authentication details, and the API proxies handle requests signed by the parent organization’s authentication details. Use this package to handle server-side interactions for applications that interact with the Turnkey API.changelogDocs
@turnkey/sdk-reactThe @turnkey/sdk-react package wraps the functionality from the @turnkey/sdk-browser package to allow developers to build react based applications that interact with the Turnkey API with different types of authentication. It allows developers to use the same clients exposed in @turnkey/sdk-browser that enable requests to the API to be authenticated via different auth methods like user sessions, passkey and iFrames. It also contains the same methods to manage information and state related to authentication like auth bundles and sessions, retrieving user information and server signing API requests. Use this package when you’re building React-based frontend applications that interact with the Turnkey API.changelogDocs

The diagram below helps visualize how each package can be used to devlop the appropriate service in your Turnkey Powered Application, and how Turnkey requests would flow between those services.

Chain/Ecosystem-Specific Signing SDK Packages

The following packages contain chain or ecosystem specific signers that take some of our Primary Turnkey Web SDK Packages (usually @turnkey/sdk-browser or @turnkey/sdk-server) and add additional support based on the signing process or transaction structure relevant to that specific chain or ecosystem.

PackageNPMDescriptionChangelog
@turnkey/ethersTurnkey Signer for Etherschangelog
@turnkey/viemTurnkey Signer for Viemchangelog
@turnkey/cosmjsTurnkey Signer for CosmJSchangelog
@turnkey/solanaTurnkey Signer for Solanachangelog
@turnkey/eip-1193-providerTurnkey-compatible EIP-1193 Providerchangelog

Advanced Functionality SDK Packages

For those with more specialized use cases, Turnkey exposes it’s lower level-libraries stamping and encryption libraries to be used directly. Note: for most use-cases, these libraries are not meant to be used directly and we encourage working on designing your application mainlyusing our Primary Turnkey Web SDK Packages along with our Chain and Ecosystem Specific SDK Packages as per your use case!

Request Stamping

PackageNPMDescriptionChangelogDocs
@turnkey/httpLower-level, fully typed HTTP client for interacting with Turnkey APIchangelogDocs
@turnkey/api-key-stamperProvide API key signatures over Turnkey requestschangelogDocs
@turnkey/iframe-stamperProvide API key signatures over Turnkey requests within iframe contextschangelogDocs
@turnkey/webauthn-stamperProvide Webauthn signatures over Turnkey requestschangelogDocs
@turnkey/wallet-stamperProvide wallet signatures over Turnkey requestschangelogDocs
@turnkey/sdk-react-native-passkey-stamperProvide Passkey signatures over Turnkey requests in a React Native contextchangelogDocs

Utilities

PackageNPMDescriptionChangelog
@turnkey/encodingEncoding and decoding utilities, primarily for internal usagechangelog
@turnkey/cryptoCryptographic utilities for P256 keys, encryption, and decryptionchangelog

Code Examples

Instant examples (powered by Stackblitz)

The following code examples have been loaded into Stackblitz web environments so you can test them out immediately

ExampleDescriptionStackblitz Link
email-auth-local-storageA NextJS app demonstrating a complete email auth flow using a locally stored target embedded keyTest it out on Stackblitz!
with-eth-passkey-signersA NextJS app powering users to create suborgs and sign messages via Viem or EthersTest it out on Stackblitz!
with-solanaCreate a new Solana address, then sign and broadcast a transaction on Solana’s devnetTest it out on Stackblitz!
with-solana-passkeysA NextJS app powering users to create suborgs, sign messages, and create transactions sponsored by the parent org using @turnkey/solanaTest it out on Stackblitz!

Other Code Examples

The below examples will require a local installation of node.js. Follow the specific instructions in the respective readme’s of each examples to run them!

ExampleDescription
demo-consumer-walletA minimal consumer wallet app powered by Turnkey and WalletConnect
demo-passkey-walletA minimal consumer wallet app powered by Turnkey and passkeys
demo-ethers-passkeysA NextJS app that demonstrates how to use @turnkey/ethers to build a passkey-powered application
demo-viem-passkeysA NextJS app that demonstrates how to use @turnkey/viem to build a passkey-powered application
react-native-demo-walletA React Native app that demonstrates how to use the Turnkey’s JavaScript packages in a mobile environment to authenticate users, create wallets, export wallets, sign messages, and more
flutter-demo-appA Flutter app that demonstrates how to use the Turnkey’s Flutter packages to authenticate users, create wallets, export wallets, sign messages, and more
deployerCompile and deploy a smart contract
email-authA NextJS app demonstrating a complete email auth flow using Turnkey iframes
wallet-import-exportA NextJS app demonstrating complete wallet import and export flows
rebalancerA demo application which showcases an example of how to use Turnkey for managing multiple types of keys & users
sweeperSweep funds from one address to a different address
trading-runnerA sample application demonstrating a trading operation, using various private keys, users, and policies, powered by Uniswap
with-ethersCreate a new Ethereum address, then sign and broadcast a transaction using the Ethers signer with Infura
with-viemSign and broadcast a transaction using the Turnkey Custom Account and Infura
with-cosmjsCreate a new Cosmos address, then sign and broadcast a transaction on Celestia testnet using the CosmJS signer
with-bitcoinCreate a new wallet, derive a BTC address, create, sign, and broadcast a transaction using BitcoinJS and other external APIs
with-biconomy-aaCreate a new wallet, connect a Turnkey wallet client to Biconomy Nexus, and create, sign, and broadcast an EIP-1559 transaction
with-zerodev-aaCreate a new wallet, instantiate a Turnkey signer, create a ZeroDev kernel account and client, and broadcast a UserOp
with-gnosisCreate new Ethereum addresses, configure a 3/3 Gnosis safe, and create + execute a transaction from it
with-uniswapSign and broadcast a Uniswap v3 trade using the Ethers signer with Infura
with-nonce-managerCreate a new Ethereum address, then sign and broadcast multiple transactions in a sequential or optimistic manner
with-offlineSign a Turnkey request in offline context
with-federated-passkeysA NextJS app that demonstrates how to use Turnkey to build a federated, webauthn powered authentication flow
with-eip-1193-providerA NextJS app that demonstrates how to use Turnkey the @turnkey/eip-1193-provider in your app
with-wallet-stamperA NextJS app that demonstrates how to use Turnkey the @turnkey/wallet-stamper in your app

Demos built with Turnkey

Demo Consumer Wallet (code)

A minimal consumer wallet app powered by Turnkey. Behind the scenes, it uses @turnkey/ethers for signing and WalletConnect (v1) for accessing dapps.

https://github.com/tkhq/demo-consumer-wallet/assets/127255904/2c3409df-2d7c-4ec3-9aa8-e2944a0b0e0a

See https://github.com/tkhq/demo-consumer-wallet for the code.

A wallet application showing how users can register and authenticate using passkeys. This demo uses the Turnkey API to create a new Turnkey Sub-Organization for each user, create a testnet Ethereum address and send a transaction on Sepolia (ETH testnet).

See https://wallet.tx.xyz (and https://github.com/tkhq/demo-passkey-wallet for the code).

Demo Ethers Passkeys (code)

A simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/ethers signer, using passkeys.

See https://github.com/tkhq/demo-ethers-passkeys for the code.

Demo Viem Passkeys (code)

A similar, simple application demonstrating how to create sub-organizations, create private keys, and sign with the @turnkey/viem signer, using passkeys.

See https://github.com/tkhq/demo-viem-passkeys for the code.

React Native Demo App (code)

A React Native app that demonstrates how to use the Turnkey’s JavaScript packages in a mobile environment to authenticate users, create wallets, export wallets, sign messages, and more

https://github.com/user-attachments/assets/e4cff012-11e9-4636-b67a-5dbf75355832

See https://github.com/tkhq/react-native-demo-wallet for the code.

Flutter Demo App (code)

A Flutter app that demonstrates how to use the Turnkey’s Flutter packages to authenticate users, create wallets, export wallets, sign messages, and more

https://github.com/user-attachments/assets/3d583ed8-1eff-4101-ae43-3c76c655e635

See https://github.com/tkhq/dart-sdk/tree/main/examples/flutter-demo-app for the code