This repository serves as a template for working with the Okto SDK in TypeScript. It provides two main approaches for integrating with Okto:
- TypeScript SDK Integration - A simple, direct way to interact with Okto services
- Direct API Integration - Detailed examples for direct API interactions with Okto
Note: These scripts are used for demonstration purposes only. DO NOT use these scripts as it is in production. Customise these scripts according to your needs.
- Features
- TypeScript SDK Usage
- Template Directories and Use Cases
- Prerequisites and Setup
- Environment Variables
- Common Issues and Troubleshooting
- Support and Resources
- π Authentication with Google Sign-In
- πΌ Wallet Management for crypto assets
- πΈ Token Transfers for sending tokens
- πΌοΈ NFT Transfers for sending NFTs
- π Raw Transaction support for custom blockchain interactions
- π Delegated Actions for advanced use cases
The main entry point for the TypeScript SDK is src/index.ts
. This file demonstrates how to:
- Initialize the Okto client
- Authenticate users with Google OAuth
- Retrieve wallet information
- Check portfolio balances
- Get supported chains and tokens
- Transfer tokens and NFTs
To use the TypeScript SDK in your own project, simply import the required functions from the Okto SDK package:
import { OktoClient } from "@okto_web3/core-js-sdk";
import { tokenTransfer, nftTransfer } from "@okto_web3/core-js-sdk/userop";
For more details on how to use the TypeScript SDK, please refer to the TypeScript SDK Setup Guide.
This template demonstrates how to use the Okto TypeScript SDK for common operations:
- Authentication: Multiple login methods (Google OAuth, Email, WhatsApp, JWT)
- Wallet Management: View and manage crypto wallets
- Portfolio Management: Check balances, view activity, and manage NFTs
- Token Operations: Transfer tokens and NFTs
- Message Signing: Support for both EIP-191 and EIP-712 message signing
- Order History: Track and manage trading orders
This template provides low-level API integration examples for advanced use cases:
Handles user authentication flows, token generation, and session management for secure access to Okto services.
googleAuthenticate_template.ts
- Google OAuth authentication implementationappleAuthenticate_template.ts
- Apple Sign-In authentication implementationtwitterAuthenticate_template.ts
- Twitter authentication implementationwhatsappAuthenticate_template.ts
- WhatsApp OTP-based authenticationemailAuthenticate_template.ts
- Email OTP-based authenticationjwtAuthenticate_template.ts
- JWT-based authenticationverifySession_template.ts
- Session verification and managementdelegatedActions_template.ts
- Delegated action implementationtreasuryWallet_template.ts
- Treasury wallet management
Implements various blockchain operations like token transfers, NFT transfers, raw transactions, and swap operations with support for gas estimation.
tokenTransfer.ts
- Basic token transfer implementationtokenTransfer_with_estimate.ts
- Token transfer with gas estimationnftTransfer.ts
- Basic NFT transfer implementationnftTransfer_with_estimate.ts
- NFT transfer with gas estimationrawTransaction.ts
- Raw transaction implementationrawTransaction_with_estimate.ts
- Raw transaction with gas estimationswapIntent.ts
- Token swap implementationsignData_template.ts
- Message and typed data signing
Provides essential tools for blockchain operations including paymaster integration, session key management, and transaction encoding/decoding.
generateUserOp.ts
- User operation generationgetAuthorizationToken.ts
- Authorization token generationgetOrderHistory.ts
- Order history retrievalgetTreasuryWalletAuthorizationToken.ts
- Treasury wallet token generationinvokeAuthenticate.ts
- Authentication invocationinvokeEstimateUserOp.ts
- User operation estimationinvokeExecuteUserOp.ts
- User operation executionsessionKey.ts
- Session key managementgenerateClientSignature.ts
- Client signature generationgenerateOktoAuthToken.ts
- Okto authentication token generationgeneratePaymasterData.ts
- Paymaster data generationgenerateSignMessagePayload.ts
- Message signing payload generation
Enables blockchain data querying, transaction monitoring, and address information retrieval for comprehensive blockchain interaction.
getAccount.ts
- Account information retrievalgetChains.ts
- Supported chains informationgetPortfolio.ts
- Portfolio balance and assetsgetPortfolioActivity.ts
- Portfolio transaction historygetTokens.ts
- Supported tokens informationreadContractData.ts
- Smart contract data reading
Offers common utility functions for data conversion, serialization, and blockchain-specific operations to simplify development.
abi.ts
- ABI encoding and decoding utilitiesconstants.ts
- Common constants and configurationnonceToBigInt.ts
- Nonce conversion utilitiesserializeJson.ts
- JSON serialization helperstypes.ts
- TypeScript type definitions
This template focuses on trading-specific functionality:
getBestRoute.ts
- Find optimal trading routesgetCallData.ts
- Generate transaction call datagetQuote.ts
- Fetch real-time trading quotesregisterIntent.ts
- Register trading intents
types.ts
- Trading-specific type definitionsaxiosClient.ts
- HTTP client configuration
- Node.js (v16 or higher)
- npm or yarn
- TypeScript (v4.5 or higher)
- Clone the repository
- Install dependencies:
npm install # or yarn install
- Copy
.env.example
to.env
and fill in your credentials:cp .env.example .env
The following environment variables are required:
# Okto environment ("sandbox" or "production")
OKTO_ENVIRONMENT=sandbox
# Okto API credentials (from Developer Dashboard)
OKTO_CLIENT_PRIVATE_KEY=
OKTO_CLIENT_SWA=
# Google authentication (optional, only for Google auth)
GOOGLE_ID_TOKEN=
# For testing intents or delegated access
USER_SWA=
SESSION_PUBLIC_KEY=
SESSION_PRIVATE_KEY=
OKTO_AUTH_TOKEN=
Contributions are welcome! Please take a moment to review our CONTRIBUTING.md guidelines before submitting any Pull Requests. Your contributions are invaluable to the Okto community.
- Okto Documentation
- Okto Developer Dashboard
- For support, join the Okto Discord Server
- Invalid Credentials: Ensure your API credentials are correctly set in the
.env
file
- Use the sandbox environment for testing
- Implement proper error handling for all API calls
- Monitor rate limits and implement appropriate backoff strategies
- Use TypeScript for better type safety and development experience