Getting started

Getting started with the Hop v2 JavaScript SDK

Install module

Using NPM:

npm install @hop-protocol/v2-sdk

Using Yarn:

yarn add @hop-protocol/v2-sdk

CDN

jsDeliver CDN:

<script src="https://cdn.jsdelivr.net/npm/@hop-protocol/v2-sdk@latest/hop.js"></script>

unpkg CDN:

<script src="https://unpkg.com/@hop-protocol/v2-sdk@latest/hop.js"></script>

Import module

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

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

SDK Setup

First, initialize the SDK with your network configuration:

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.

1. Initialize SDK

First, set up your connection and token details:

2. Check Token Approval

Before sending tokens, check if approval is needed:

3. Send Tokens

Calculate fees and send the tokens:

4. Monitor Transfer Status

After sending tokens, monitor the transfer status:

5. Handle Transfer Completion

The transfer can complete in two ways:

Option A: Bonded Transfer (Automatic)

If a bonder picks up your transfer, it will automatically be completed on the destination chain. The status will change to 'Bonded'.

Option B: Manual Claim (If not bonded)

If the transfer isn't bonded after some time, you can manually claim it:

Additional Functions

Calculate Fees

Estimate Gas

Event Handling

Monitor transfer-related events:

Types

Key types for transfer operations:

More examples

If you'd like to see more examples or have any feedback, message us on Discord!

SDK API Reference

API Reference

Contract addresses

Contract Addresses

Last updated