Integrating Turnkey with Adamik API
This guide demonstrates how to integrate Turnkey’s secure signing infrastructure with the Adamik API. By following this implementation, you can leverage Turnkey’s institutional-grade key management system to sign transactions across all Adamik-supported blockchains.
Overview
The integration showcases how Turnkey can be combined with Adamik API to:
- Securely manage cryptographic keys in a custodial environment
- Sign transactions for 60+ blockchains with enterprise-grade security
- Automatically handle different signature formats and curves across chains
The complete source code for this implementation is available in our GitHub repository.
Prerequisites
To use Turnkey with Adamik API, you’ll need:
- A Turnkey account with API credentials (you can create one here)
- A wallet created in the Turnkey interface (required to obtain your wallet ID)
- Environment variables properly set up (see below)
Environment Setup
Depending on your project structure, you’ll need to set up environment variables slightly differently:
For frontend projects (like adamik-tutorial):
For backend/Node.js projects (like adamik-link):
Implementing the Turnkey Signer
The core of the integration is the TurnkeySigner
class, which implements the BaseSigner
interface:
Here’s a complete implementation:
Integration Workflow
The typical workflow for using Turnkey with Adamik API follows these steps:
- Initialize the Signer:
- Generate/Retrieve Public Key:
- Convert to Address (using Adamik API):
- Prepare a Transaction (using Adamik API):
- Sign Transaction:
- Broadcast Transaction (using Adamik API):
Key Features
Automatic Account Creation
The Turnkey signer automatically creates accounts with the correct derivation paths and address formats based on the blockchain requirements. If an account already exists, it retrieves it:
Multi-Curve Support
The signer handles different cryptographic curves required by various blockchains:
Error Handling
The implementation includes proper error handling for common scenarios, including the case where an account exists but wasn’t found in the initial lookup:
Troubleshooting Common Issues
”Wallet account corresponding to path already exists”
This error occurs when trying to create an account that already exists. The signer implementation handles this by:
- Catching the error
- Fetching the accounts again
- Finding the existing account with the matching path
Missing Environment Variables
If you encounter errors related to missing environment variables, check:
- For frontend projects: Ensure variables start with
VITE_
- For backend projects: No prefix needed
- Verify all required variables are defined in your
.env
file - Restart your application after updating environment variables
Authentication Issues
If you experience authentication problems:
- Verify your API keys are correct
- Ensure your organization ID and wallet ID are properly set
- Check that your Turnkey account has necessary permissions
Security Considerations
When implementing Turnkey with Adamik API, consider these security best practices:
- Environment Variables: Never hardcode API credentials
- Error Handling: Implement proper error handling for API responses
- Key Management: Use appropriate key derivation paths for each blockchain
- Logging: Implement comprehensive logging for audit purposes, but avoid logging sensitive information
Testing the Integration
To test this integration:
- Clone the GitHub repository
- Create a
.env.local
file based on the.env.local.example
- Set up your Turnkey environment variables
- Run the example code to test transactions on different chains
Conclusion
The integration of Turnkey with Adamik API provides a secure and scalable solution for multi-chain applications. By following this implementation guide, you can leverage Turnkey’s institutional-grade security while maintaining the flexibility to operate across multiple blockchains through a single interface.
For more details, explore the full source code in our GitHub repository, particularly the src/signers/Turnkey.ts
file for the implementation details.
Was this page helpful?