Skip to content

This is a template repo for users to understand the functionality and usage of Okto SDK for dapps built on TS or to integrate okto on nodejs backend

License

Notifications You must be signed in to change notification settings

okto-hq/okto-sdkv2-ts-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Okto SDK TypeScript Template

This repository serves as a template for working with the Okto SDK in TypeScript. It provides two main approaches for integrating with Okto:

  1. TypeScript SDK Integration - A simple, direct way to interact with Okto services
  2. 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.

Table of Contents

Features

  • πŸ” 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

TypeScript SDK Usage

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.

Template Directories and Use Cases

1. TypeScript SDK Template (src/ts-sdk-template/)

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

2. API Template (src/api-template/)

This template provides low-level API integration examples for advanced use cases:

Authentication (auth/)

Handles user authentication flows, token generation, and session management for secure access to Okto services.

Intents (intents/)

Implements various blockchain operations like token transfers, NFT transfers, raw transactions, and swap operations with support for gas estimation.

Utilities (utils/)

Provides essential tools for blockchain operations including paymaster integration, session key management, and transaction encoding/decoding.

Explorer (explorer/)

Enables blockchain data querying, transaction monitoring, and address information retrieval for comprehensive blockchain interaction.

Helpers (helper/)

Offers common utility functions for data conversion, serialization, and blockchain-specific operations to simplify development.

3. Trade Service (src/trade-service/)

This template focuses on trading-specific functionality:

API Integration (api/)

Utilities (utils/)

Prerequisites and Setup

Required Tools

  • Node.js (v16 or higher)
  • npm or yarn
  • TypeScript (v4.5 or higher)

Environment Setup

  1. Clone the repository
  2. Install dependencies:
    npm install
    # or
    yarn install
  3. Copy .env.example to .env and fill in your credentials:
    cp .env.example .env

Environment Variables

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=

Contributing

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.

Learn More

Common Issues and Troubleshooting

Authentication Issues

  • Invalid Credentials: Ensure your API credentials are correctly set in the .env file

Development Tips

  • 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

Support and Resources

About

This is a template repo for users to understand the functionality and usage of Okto SDK for dapps built on TS or to integrate okto on nodejs backend

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 7