The Okto React SDK is a powerful tool designed to onboard users to the Web3 ecosystem seamlessly within React applications. With minimal setup, developers can integrate multi-chain Web3 capabilities into their apps, including wallet management, token operations, and advanced smart contract interactions. This guide provides a comprehensive walkthrough for developers and contributors to get started, implement core features, and contribute to the SDK’s development.
- Features
- Prerequisites
- Installation
- Configuration
- Core Features
- Advanced Features
- Error Handling
- Contributing to the SDK
- API Reference
- Troubleshooting
- Support
- EVM-Compatible Chains: Ethereum, Polygon, Binance Smart Chain, and others.
- Non-EVM Chains: Solana, Aptos.
- Upcoming Support: Cosmos ecosystem.
- Authentication: Options include Google OAuth, Email OTP, and Phone OTP.
- Wallet Management: Create, manage, and interact with multiple wallets.
- Token Operations: Transfer and manage various tokens seamlessly.
- NFT Integration: Mint, transfer, and manage NFTs.
- Smart Contract Interactions: Directly interact with smart contracts.
- Portfolio Management: Track digital assets efficiently.
- Customizable UI: Easily adapt designs to match your application.
- Node.js and npm (or yarn) installed.
- React application setup with a compatible version.
- Required dependencies installed (see Installation).
- Okto API Key: Obtainable from the Okto Developer Dashboard.
- Google OAuth Credentials: Required for authentication.
- Sandbox Environment: Default for testing and development.
- Production Environment: Enabled through the Admin Panel.
npm install okto-sdk-react @react-oauth/google axios
For a preconfigured React app:
npx create-okto-app@latest
cd my-okto-app
npm install
npx create-okto-app@latest
# Select Next.js template
cd my-okto-app
npm install
Create a .env
file in the project root:
REACT_APP_GOOGLE_CLIENT_ID=your_google_client_id
REACT_APP_OKTO_CLIENT_API_KEY=your_okto_api_key
Wrap your app with the OktoProvider
in index.js
:
import React from 'react';
import ReactDOM from 'react-dom/client';
import { GoogleOAuthProvider } from '@react-oauth/google';
import { OktoProvider, BuildType } from 'okto-sdk-react';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<GoogleOAuthProvider clientId={process.env.REACT_APP_GOOGLE_CLIENT_ID}>
<OktoProvider apiKey={process.env.REACT_APP_OKTO_CLIENT_API_KEY} buildType={BuildType.SANDBOX}>
<App />
</OktoProvider>
</GoogleOAuthProvider>
</React.StrictMode>
);
Authenticate users with Google OAuth for seamless onboarding:
import { GoogleLogin } from '@react-oauth/google';
import { useOkto } from 'okto-sdk-react';
const Login = () => {
const { authenticate } = useOkto();
const handleGoogleLogin = async (response) => {
try {
await authenticate(response.credential);
console.log('User authenticated successfully!');
} catch (err) {
console.error('Authentication failed:', err);
}
};
return <GoogleLogin onSuccess={handleGoogleLogin} />;
};
Create and manage wallets:
const Wallets = () => {
const { getWallets, createWallet } = useOkto();
const [wallets, setWallets] = React.useState([]);
React.useEffect(() => {
const fetchWallets = async () => {
const userWallets = await getWallets();
setWallets(userWallets);
};
fetchWallets();
}, []);
const addWallet = async () => {
const newWallet = await createWallet();
setWallets((prev) => [...prev, newWallet]);
};
return (
<div>
<button onClick={addWallet}>Create Wallet</button>
{wallets.map((wallet) => (
<p key={wallet.address}>Address: {wallet.address}</p>
))}
</div>
);
};
Transfer tokens across supported networks:
const Transfer = () => {
const { transferTokens } = useOkto();
const handleTransfer = async () => {
try {
await transferTokens({
network_name: 'Ethereum',
token_address: '0xTokenAddress',
recipient_address: '0xRecipientAddress',
quantity: '1',
});
console.log('Transfer successful!');
} catch (err) {
console.error('Transfer failed:', err);
}
};
return <button onClick={handleTransfer}>Transfer Tokens</button>;
};
- Clone the repository:
git clone https://github.com/okto-hq/okto-sdk-react.git cd okto-sdk-react
- Install dependencies:
npm install
- Run tests locally:
npm test
- Write clear, concise, and reusable code.
- Adhere to the existing coding standards.
- Document new features and provide example implementations.
Submit issues or feature requests via GitHub. Ensure you provide clear steps to reproduce bugs or detailed descriptions for feature suggestions.
authenticate(idToken: string): Promise<AuthResponse>;
logout(): void;
isLoggedIn(): boolean;
getWallets(): Promise<Wallet[]>;
createWallet(): Promise<Wallet>;
getPortfolio(): Promise<Portfolio>;
transferTokens(data: TransferData): Promise<TransactionReceipt>;
getSupportedTokens(): Promise<Token[]>;
- Authentication Errors: Verify API keys and OAuth credentials.
- Transaction Failures: Check network configurations and wallet balances.
- Network Connectivity: Ensure proper RPC endpoints are configured.
- Use browser dev tools to monitor network requests.
- Log SDK responses for debugging purposes.
- Documentation: Okto SDK Docs
- Email: support@okto.tech
Built with ❤️ by the Okto team.