Getting started
⚠️ JavaScript SDK is in beta
Install module
Using NPM:
Using Yarn:
CDN
jsDeliver CDN:
unpkg CDN:
Import module
Import as ES6 module (e.g. Using TypeScript, babel, webpack):
Import as commonJS module (e.g. Using Node.js directly or no ES6 modules):
Instantiate SDK
Avaiable networks are only goerli
at this time.
Send Message
Send a message from one chain to another chain.
Use this method to get the populated transaction for sending a message.
Method: getSendMessagePopulatedTx
Parameters
fromChainId
number
The origin chain the message will be sent from.
eg. 420
toChainId
number
This is the destination chain where the message should be received.
eg. 5
toAddress
string
The address to call at the destination.
eg. 0x5f335A890bbB5Cd1a4a7f7A1C8F9F6F75efDCA89
toCalldata
string
The tx calldata to execute at the destination address.
eg. 0x812448a5000000000000000000000000000000000000000000000000000000000000002a
Response
data
string
Calldata
eg. 0x7056f41f00...
to
string
Address
eg. 0xeA35E10f763ef2FD5634dF9Ce9ad00434813bddB
chainId
number
Chain ID
eg. 420
value
string
Message fee value as wei
eg. 1000000000000
Example
Get Bundle Proof
Get bundle proof needed to relay message at destination chain.
Use this method to get the bundle proof JSON.
Method: getBundleProofFromMessageId
Parameters
fromChainId
number
The origin chain the message was sent from.
eg. 420
toChainId
number
The destination chain specified for the message.
eg. 5
messageId
string
The message ID hash. This is emitted in the MessageSent
event.
eg. 0xe8e4885871d370ef17693db9fc0f34bda218c8685a9bb3ab40648cf8d2a5358e
Response
bundleId
string
Bundle ID
eg. 0x5e26c4282d410e7e0c892561566ce0a6522f4762de1fc59d9bfba068890d9f7d
treeIndex
number
Message tree index
eg. 2
siblings
string[]
Proof sibling nodes
eg. ["0xf672a68db7...", "0xb93f64fa40..."]
totalLeaves
number
Total leaves that make up root
eg. 4
Example
Relay Message
Relay and execute message at the destination
Use this method to get the populated transaction for relaying a message.
Method: getRelayMessagePopulatedTx
Parameters
fromChainId
number
The origin chain the message was sent from.
eg. 420
toChainId
number
The destination chain specified for the message.
eg. 5
from
string
The sender address that sent the original message.
eg. 0x9997da3de3ec197C853BCC96CaECf08a81dE9D69
toCalldata
string
The destination calldata specified when sending the message.
eg. 0x812448a5000000000000000000000000000000000000000000000000000000000000002a
bundleProof
object
The bundle proof JSON which can be generated by calling the getBundleProofFromMessageId
method.
eg. { "bundleId": "0x5e26c4282d4...", "treeIndex": 2, "siblings": [ "0xb93f64fa4...." ], "totalLeaves": 3 }
Response
data
string
Calldata
eg. 0x7ad7be77000000000...
to
string
Address
eg. 0xE3F4c0B210E7008ff5DE92ead0c5F6A5311C4FDC
chainId
number
Chain ID
eg. 5
Example
Exit Bundle
Exit bundle at the destination.
Use this method to get the populated transaction for exiting a bundle.
Method: getBundleExitPopulatedTx
Parameters
fromChainId
number
The origin chain of the message route.
eg. 420
bundleCommittedTransactionHash
string
The transaction hash that has the BundleCommitted
event of the bundleId to exit.
eg. 0xf7aa4bccf0ffe34d76ceb1f18864a2dbfd590bdfca44ad29a316079559327020
Response
data
string
Calldata
eg. 0x7ad7be77000000000...
to
string
Address
eg. 0xE3F4c0B210E7008ff5DE92ead0c5F6A5311C4FDC
chainId
number
Chain ID
eg. 5
Example
Get Message ID
Get Message ID from transaction hash.
Method: getMessageIdFromTransactionHash
Parameters
fromChainId
number
The origin chain of the message.
eg. 420
transactionHash
string
The tx hash that contains the MessageSent
event.
eg. 0xdccaf2fc42186d66f72869ecb12b0be1f9b9c018a43a13f4ff32ee3eaa0d943c
Response
messageId
string
Message ID
eg. 0xf672a68db7ebbac6e28bc217967a83d5fc63f0f185a9c25b1693a3afb445a696
Example
Get Message Calldata
Get calldata of message given message ID
Method: getMessageCalldata
Parameters
fromChainId
number
The origin chain of the message.
eg. 420
messageId
string
The messageId
from the MessageSent
event
eg. 0xf672a68db7ebbac6e28bc217967a83d5fc63f0f185a9c25b1693a3afb445a696
Response
calldata
string
Calldata of message
eg. 0x812448a5000000000000000000000000000000000000000000000000000000000000002a
Example
Get Message Sent Event
Get full event log from message ID
Method: getMessageSentEventFromMessageId
Parameters
fromChainId
number
From chain ID
eg. 420
messageId
string
The messageId
from the MessageSent
event
eg. 0xf672a68db7ebbac6e28bc217967a83d5fc63f0f185a9c25b1693a3afb445a696
Response
event
object
Message event log
eg. {"messageId": "0xf672a68d...", "from": "0x651...", "toChainId": 5, ...}
Example
Get Message Fee
Get fee in wei required to send message
Method: getMessageFee
Parameters
fromChainId
number
The origin chain the message will be sent from.
eg. 420
toChainId
number
The destination chain for the message.
eg. 5
Response
value
string
Message fee in wei
eg. 1000000000000
Example
Get Events
Get decoded events for hub and spoke contracts.
Method: getEvents
Parameters
eventNames
string[]
List of event names to fetch. Options are: ["BundleCommitted","BundleForwarded","BundleReceived","BundleSet","FeesSentToHub","MessageBundled","MessageRelayed","MessageReverted","MessageSent"]
eg. ["MessageSent", "MessageBundled"]
chainId
number
Chain ID
eg. 420
fromBlock
number
From block number
eg. 4554675
toBlock
number
To block number
eg. 4555675
Response
events
object[]
Event logs
eg. [{"eventName": "MessageSent", ... }]
Example
Set Contract Addresses
Set contract addresses config for sdk
Method: setContractAddresses
Parameters
chainId
number
Chain ID of messenger contract.
eg. 420
startBlock
number
Block contract was deployed at. This is used as start block when fetching events.
eg. 420
spokeCoreMessenger
string
The address of the SpokeCoreMessenger contract.
eg. 0xE3F4c0B210E7008ff5DE92ead0c5F6A5311C4FDC
Response
void
Example
Get Contract Addresses
Get hub and spoke contract addresses sdk is using.
Method: getContractAddresses
Parameters
None
Response
chainId
number
Chain ID of messenger contract.
eg. 420
startBlock
number
Block contract was deployed at. This is used as start block when fetching events.
eg. 420
spokeCoreMessenger
string
The address of the SpokeCoreMessenger contract.
eg. 0xE3F4c0B210E7008ff5DE92ead0c5F6A5311C4FDC
Example
Set RPC Providers
Set custom RPC Providers config
Method: setRpcProviders
Parameters
<chainId>
string
Chain ID
eg. "420"
<rpcUrl>
string
RPC URL
eg. "https://goerli.optimism.io"
Response
void
Example
More examples
If you'd like to see more examples or have any feedback, message us on Discord!
SDK API Reference
API ReferenceContract addresses
https://github.com/hop-protocol/v2-docs/blob/master/smart-contracts/contract-addresses.mdLast updated