@yativo/crypto-sdk
v1.0.3
Published
Official Yativo Crypto SDK for JavaScript/TypeScript
Maintainers
Readme
Yativo Crypto SDK
Official JavaScript/TypeScript SDK for the Yativo Crypto Platform. Seamlessly integrate cryptocurrency wallets, transactions, and blockchain operations into your application.
Features
- 🔐 Passwordless Authentication - OTP, 2FA (TOTP), passkeys, and API keys
- ⚡ USDC on Solana - ~2–5 second finality, low fees
- ⚡ USDC on XDC - ~2 second finality, near-zero fees
- 💼 Account Management - Create and manage user accounts
- 💰 Wallet Operations - Multi-chain wallet creation and management
- 🔄 Transactions - Send, receive, and track crypto transactions
- 🔔 Webhooks - Real-time event notifications
- 🔑 API Key Management - Secure programmatic access
- 🛡️ Type Safety - Full TypeScript support
Installation
npm install @yativo/crypto-sdk
# or
yarn add @yativo/crypto-sdk
# or
pnpm add @yativo/crypto-sdkQuick Start
Initialize the SDK
import YativoSDK from '@yativo/crypto-sdk';
// Initialize with API credentials
const yativo = new YativoSDK({
apiKey: 'your-api-key',
apiSecret: 'your-api-secret',
baseURL: 'https://crypto-api.yativo.com', // Optional, defaults to production
});
// Or initialize without credentials (for registration/login)
const yativo = new YativoSDK();Authentication
Yativo uses passwordless authentication. There is no password — users verify their identity via a one-time code sent to their email, an authenticator app (2FA), or a passkey.
Step 1 — Request OTP
// Sends a one-time code to the user's email
await yativo.auth.login('[email protected]');Step 2 — Verify OTP
// Verify the email OTP — returns access token
const response = await yativo.auth.verifyOTP('123456');
// Or verify with a 2FA authenticator code if the account has 2FA enabled
const response = await yativo.auth.verify2FA('654321');Passkey Authentication
// Get passkey challenge, complete WebAuthn ceremony client-side, then verify
const options = await yativo.auth.passkeyOptions('[email protected]');
// ... complete WebAuthn assertion client-side ...
const response = await yativo.auth.passkeyVerify(options);Server-to-Server (API Key)
// Authenticate with API key + secret — no OTP required
const yativo = new YativoSDK({
apiKey: process.env.YATIVO_API_KEY,
apiSecret: process.env.YATIVO_API_SECRET,
baseURL: 'https://crypto-api.yativo.com',
});Using Existing Token
const yativo = new YativoSDK();
yativo.setAccessToken('your-existing-jwt-token');Account Management
Create an Account
const { account } = await yativo.accounts.create({
account_name: 'My Trading Account',
account_type: 'personal',
});
console.log(account.account_id);List Accounts
const { accounts } = await yativo.accounts.list();
accounts.forEach(account => {
console.log(`${account.account_name}: ${account.account_id}`);
});Asset/Wallet Management
Create a USDC on Solana Wallet
// USDC on Solana — ~2–5 second finality
const { asset } = await yativo.assets.create({
account_id: 'account-id',
chain: 'solana',
ticker: 'USDC_SOL',
});
console.log(`Solana address: ${asset.wallet_address}`);Create a USDC on XDC Wallet
// USDC on XDC — ~2 second finality, ultra-low fees
const { asset } = await yativo.assets.create({
account_id: 'account-id',
chain: 'xdc',
ticker: 'USDC_XDC',
});
console.log(`XDC address: ${asset.wallet_address}`);Create Multiple Wallets
// Create wallets for multiple chains
const { assets } = await yativo.assets.createBatch({
account_id: 'account-id',
chains: ['ethereum', 'bitcoin', 'polygon'],
});
assets.forEach(asset => {
console.log(`${asset.ticker} - ${asset.address}`);
});Get Wallet Balance
const { balance } = await yativo.assets.getBalance('asset-id');
console.log(`${balance.ticker}: ${balance.balance} ($${balance.usd_value})`);List User Wallets
const { assets } = await yativo.assets.list({
account_id: 'account-id', // Optional filter
});Transactions
Send Cryptocurrency
const { transaction } = await yativo.transactions.send({
from_asset_id: 'your-wallet-asset-id',
to_address: '0x742d35Cc6634C0532925a3b844Bc454e4438f44e',
amount: '0.1',
chain: 'ethereum',
ticker: 'ETH',
priority: 'medium', // low, medium, high
});
console.log(`Transaction Hash: ${transaction.tx_hash}`);
console.log(`Status: ${transaction.status}`);Get Gas Fee Estimate
const gasFee = await yativo.transactions.getGasFee({
chainType: 'ethereum',
priority: 'medium',
amount_usd: '100',
token_symbol: 'ETH',
});
console.log(`Gas Fee: ${gasFee.total_gas_fee} ETH ($${gasFee.total_gas_fee_usd})`);List Transactions
const { data, pagination } = await yativo.transactions.list({
page: 1,
limit: 20,
status: 'completed',
type: 'send',
});
console.log(`Total: ${pagination.total} transactions`);Get Transaction Details
const { transaction } = await yativo.transactions.get('transaction-id');
console.log(transaction);Webhooks
Create a Webhook
const { webhook } = await yativo.webhooks.create({
url: 'https://your-app.com/webhooks/yativo',
events: ['transaction.completed', 'deposit.received', 'withdrawal.completed'],
description: 'Production webhook',
});
console.log(`Webhook Secret: ${webhook.secret}`); // Save this securelyList Webhooks
const { webhooks } = await yativo.webhooks.list();Verify Webhook Signature (in your webhook handler)
import { Webhooks } from '@yativo/crypto-sdk';
// In your Express/Next.js webhook handler
app.post('/webhooks/yativo', (req, res) => {
const signature = req.headers['x-yativo-signature'];
const payload = JSON.stringify(req.body);
const secret = 'your-webhook-secret';
const isValid = Webhooks.verifySignature(payload, signature, secret);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
// Process webhook event
const event = req.body;
console.log(`Event: ${event.type}`, event.data);
res.status(200).send('OK');
});API Key Management
Create API Key (Requires 2FA)
const { api_key } = await yativo.apiKeys.create({
name: 'Production API Key',
permissions: ['read', 'write', 'withdraw'],
expires_in_days: 90,
two_factor_token: '123456', // Google Authenticator code
});
console.log(`API Key: ${api_key.api_key}`);
console.log(`API Secret: ${api_key.api_secret}`); // Only shown once - save securely!List API Keys
const { api_keys } = await yativo.apiKeys.list();
api_keys.forEach(key => {
console.log(`${key.name}: ${key.status} (Last used: ${key.last_used})`);
});Revoke API Key
await yativo.apiKeys.revoke('key-id', '123456'); // Requires 2FAError Handling
All SDK methods throw errors with detailed information:
try {
const { transaction } = await yativo.transactions.send({
from_asset_id: 'asset-id',
to_address: 'invalid-address',
amount: '1.0',
chain: 'ethereum',
ticker: 'ETH',
});
} catch (error) {
console.error('Error Code:', error.code);
console.error('Error Message:', error.error);
console.error('Details:', error.details);
}TypeScript Support
The SDK is written in TypeScript and includes full type definitions:
import YativoSDK, {
Transaction,
Asset,
Account,
SendFundsRequest,
YativoError
} from '@yativo/crypto-sdk';
// All types are exported and fully typed
const sdk = new YativoSDK();
// TypeScript will autocomplete and type-check everything
const result: { success: boolean; transaction: Transaction } =
await sdk.transactions.send({...});Advanced Usage
Custom Base URL (for development/staging)
const yativo = new YativoSDK({
baseURL: 'http://localhost:3000', // Your local backend
timeout: 60000, // 60 second timeout
});Using with API Keys (Server-Side)
const yativo = new YativoSDK({
apiKey: process.env.YATIVO_API_KEY,
apiSecret: process.env.YATIVO_API_SECRET,
baseURL: 'https://crypto-api.yativo.com',
});
// No OTP needed — API keys authenticate automatically
const { assets } = await yativo.assets.list();Token Refresh
The SDK automatically handles token refresh when the access token expires:
const yativo = new YativoSDK();
// Authenticate once (passwordless)
await yativo.auth.login('[email protected]');
await yativo.auth.verifyOTP('123456');
// SDK will automatically refresh token when needed
await yativo.transactions.list(); // Works even after token expiresIdempotency for Transactions
Transactions are automatically idempotent to prevent duplicates:
// Same transaction won't be sent twice
const tx1 = await yativo.transactions.send({
from_asset_id: 'asset-id',
to_address: '0x...',
amount: '1.0',
chain: 'ethereum',
ticker: 'ETH',
idempotency_key: 'unique-key-123', // Optional - auto-generated if not provided
});
// If retried with same idempotency_key, returns original transaction
const tx2 = await yativo.transactions.send({
from_asset_id: 'asset-id',
to_address: '0x...',
amount: '1.0',
chain: 'ethereum',
ticker: 'ETH',
idempotency_key: 'unique-key-123',
});
console.log(tx1.transaction_id === tx2.transaction_id); // trueSupported Assets
| Asset | Chain | Finality | |-------|-------|----------| | USDC_SOL | Solana | ~2–5 seconds | | USDC_XDC | XDC Network | ~2 seconds, near-zero fees | | USDC | Ethereum | ~12 seconds | | USDC_POLYGON | Polygon | ~2 seconds | | USDC_ARBITRUM | Arbitrum | ~1 second | | USDC_BASE | Base | ~2 seconds | | And more... | | |
Query available chains:
const { chains } = await yativo.assets.getChains();
chains.forEach(chain => {
console.log(`${chain.name}: ${chain.supported_tokens.join(', ')}`);
});Resources
License
MIT © Yativo
Contributing
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
