@leapwallet/ondo-gm-evm-client
v1.0.1
Published
EVM client for Ondo protocol smart contract interactions - provides Ethereum connectivity, transaction execution, and type-safe contract interfaces
Downloads
2
Readme
@leapwallet/ondo-gm-evm-client
EVM client for Ondo protocol smart contract interactions - provides Ethereum connectivity, transaction execution, and type-safe contract interfaces.
Features
- 🔗 Ethereum Client: Full EVM client implementation with transaction support
- 📝 Type-Safe Contracts: Auto-generated TypeScript interfaces from ABI definitions
- ⛽ Gas Management: Automatic gas estimation and transaction preparation
- 🔐 EIP-712 Support: Type-safe structured data signing
- 🛠 Utility Functions: Error handling, data processing, and validation helpers
Installation
npm install @leapwallet/ondo-gm-evm-client @leapwallet/ondo-gm-core ethers
# or
pnpm add @leapwallet/ondo-gm-evm-client @leapwallet/ondo-gm-core ethers
# or
yarn add @leapwallet/ondo-gm-evm-client @leapwallet/ondo-gm-core ethersQuick Start
Basic Setup
import { ethers } from 'ethers';
import { EvmClient } from '@leapwallet/ondo-gm-evm-client';
// Setup provider and signer
const provider = new ethers.JsonRpcProvider('https://mainnet.infura.io/v3/your-key');
const signer = new ethers.Wallet('your-private-key', provider);
// Initialize the EVM client
const evmClient = new EvmClient({
provider,
signer,
contractAddress: '0x...', // Ondo GM contract address
feeTokenAddress: '0x...', // Fee token contract address
chainId: '1', // Ethereum mainnet
});Prepare Transactions
import type { TransactionParams } from '@leapwallet/ondo-gm-core';
const transactionParams: TransactionParams = {
chainId: '1',
fromAddress: '0x123...',
toAddress: '0x456...',
amount: '1000000', // 1 USDC (6 decimals)
// ... other attestation fields
};
// Prepare the transaction with gas estimates
const preparedTx = await evmClient.prepareTransaction(transactionParams);
console.log('Estimated gas:', preparedTx.estimatedGas);
console.log('Transaction data:', preparedTx.data);Execute Transactions
// Execute the prepared transaction
const result = await evmClient.executeTransaction(preparedTx);
console.log('Transaction hash:', result.transactionHash);
console.log('Status:', result.status); // 'pending' | 'success' | 'failed'
// Wait for confirmation
if (result.status === 'pending') {
const finalResult = await evmClient.waitForTransaction(result.transactionHash);
console.log('Final status:', finalResult.status);
}Contract Interactions
// Access the underlying contract instances
const ondoContract = evmClient.getOndoContract();
const erc20Contract = evmClient.getERC20Contract();
// Check allowance
const allowance = await erc20Contract.allowance(
'0x...', // owner address
'0x...' // spender address
);
// Get contract information
const tokenManager = await ondoContract.getFunction('tokenManager');
console.log('Token manager address:', tokenManager);API Reference
EvmClient Class
Constructor
new EvmClient({
provider: Provider, // ethers.js provider
signer: Signer, // ethers.js signer
contractAddress: string, // Ondo GM contract address
feeTokenAddress: string, // Fee token contract address
chainId: string, // Chain ID
});Methods
Transaction Management
prepareTransaction(params)- Prepare transaction with gas estimatesexecuteTransaction(prepared)- Execute a prepared transactionwaitForTransaction(hash)- Wait for transaction confirmation
Contract Access
getOndoContract()- Get the Ondo protocol contract instancegetERC20Contract()- Get the ERC20 token contract instance
Utility Methods
estimateGas(params)- Estimate gas for transactionvalidateTransaction(params)- Validate transaction parameters
Type Definitions
// Transaction arguments for EVM operations
type EthTransactionArg = [
quote: IGMTokenManager.QuoteStruct,
signature: BytesLike,
depositToken: AddressLike,
depositAmount: BigNumberish,
];
// Prepared transaction for Ethereum
interface EthPreparedTransaction {
chainId: string;
data: EthTransactionArg;
estimatedGas: string;
gasPrice?: string;
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
}Contract Interfaces
The package includes auto-generated TypeScript interfaces for all contract interactions:
Ondo Contract (IGMTokenManager)
// Mint tokens
await ondoContract.mint(quote, signature, depositToken, depositAmount);
// Get token manager
const tokenManager = await ondoContract.tokenManager();
// Check if address is sanctioned
const isSanctioned = await ondoContract.sanctionsList('0x...');ERC20 Contract
// Check balance
const balance = await erc20Contract.balanceOf('0x...');
// Check allowance
const allowance = await erc20Contract.allowance('0x...', '0x...');
// Approve tokens
await erc20Contract.approve('0x...', amount);Error Handling
import { TxClientError } from '@leapwallet/ondo-gm-core';
try {
const result = await evmClient.executeTransaction(preparedTx);
} catch (error) {
if (error instanceof TxClientError) {
console.error('Transaction error:', error.message);
console.error('Error code:', error.code);
} else {
console.error('Unexpected error:', error);
}
}Gas Optimization
// Custom gas settings
const preparedTx = await evmClient.prepareTransaction(params, {
gasLimit: '200000', // Custom gas limit
maxFeePerGas: '20000000000', // 20 gwei
maxPriorityFeePerGas: '2000000000', // 2 gwei
});Network Support
The EVM client supports all Ethereum-compatible networks:
- Ethereum Mainnet (chainId: '1')
- Polygon (chainId: '137')
- Arbitrum (chainId: '42161')
- Optimism (chainId: '10')
- Base (chainId: '8453')
- Test networks (Goerli, Sepolia, etc.)
Integration Examples
With React Adapter
// In your React hook
import { useOndoEvmClient } from '@leapwallet/ondo-gm-react-adapter';
function useCustomTransaction() {
const evmClient = useOndoEvmClient();
return async (params: TransactionParams) => {
const prepared = await evmClient.prepareTransaction(params);
return evmClient.executeTransaction(prepared);
};
}With Wagmi
import { useWalletClient } from 'wagmi';
import { clientToSigner } from '@leapwallet/ondo-gm-react-adapter';
function useEvmClientFromWagmi() {
const { data: walletClient } = useWalletClient();
return useMemo(() => {
if (!walletClient) return null;
const signer = clientToSigner(walletClient);
return new EvmClient({
provider: signer.provider,
signer,
contractAddress: '0x...',
feeTokenAddress: '0x...',
chainId: walletClient.chain.id.toString(),
});
}, [walletClient]);
}Dependencies
ethers- Ethereum library for blockchain interactions@leapwallet/ondo-gm-core- Core types and interfacesbignumber.js- Arbitrary precision arithmetic
License
ISC
