Import as ES6 module (e.g. Using TypeScript, babel, webpack):
import { Hop } from '@hop-protocol/v2-sdk'
Import as commonJS module (e.g. Using Node.js directly or no ES6 modules):
const { Hop } = require('@hop-protocol/v2-sdk')
Instantiate SDK
import { Hop } from '@hop-protocol/v2-sdk'
const hop = new Hop({ network: 'sepolia' })
Avaiable networks are only sepolia at this time.
Hop V2 SDK Documentation
The Hop V2 SDK provides a simple interface for interacting with the Hop Protocol V2. This documentation will help you get started with integrating the SDK into your application.
Table of Contents
Installation
SDK Setup
Complete Transfer Flow
1. Initialize SDK
2. Check Token Approval
3. Send Tokens
4. Monitor Transfer Status
5. Handle Transfer Completion
Additional Functions
Event Handling
Types
Best Practices
Installation
npm install @hop-protocol/v2-sdk
SDK Setup
First, initialize the SDK with your network configuration:
import { Hop } from '@hop-protocol/v2-sdk'
import { providers } from 'ethers'
const hop = new Hop({
network: 'mainnet', // or 'sepolia' for testnet
signersOrProviders: {
'1': new providers.JsonRpcProvider('ETHEREUM_RPC_URL'),
'10': new providers.JsonRpcProvider('OPTIMISM_RPC_URL'),
// Add other chains as needed
}
})
Constructor Options
Parameter
Type
Description
Required
network
string
Network name ('mainnet' or 'sepolia')
No
signersOrProviders
SignersOrProviders
Map of chain IDs to ethers signers/providers
Yes
contractAddresses
Addresses
Custom contract addresses
No
batchBlocks
number
Number of blocks to batch in queries
No
Complete Transfer Flow
Let's walk through the complete process of transferring tokens from one chain to another.