Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 1.8 KB

contract-interaction.md

File metadata and controls

45 lines (33 loc) · 1.8 KB
description
Interact with your application on multiple chains

App Abstraction

The Hyperlane SDK simplifies the interface for smart contract applications deployed across multiple chains. It provides utilties for invoking a contract's methods on a target chain and a MultiProvider for managing chain connections.

Implement

The HyperlaneApp abstraction is a mapping that resolves a chain to a collection of ethers Contracts. Developers should extend HyperlaneApp and can add methods for different kinds of contract calls/transactions they would like to initiate.

A simple HyperlaneApp extension could look like this:

export class MyHyperlaneApp<Chain extends ChainName = ChainName> 
  extends HyperlaneApp<MyContracts, Chain> 
{
  async myMethod(from: Chain, to: Chain, message: string) {
    const myContract = this.getContracts(from).router;
    const toDomain = ChainNameToDomainId[to];
    const tx = await helloWorldContract.myMethod(toDomain, message);
    return tx.wait();
  }
}

{% hint style="info" %} See the Hyperlane Hello World app for an example of how to extend HyperlaneApp. {% endhint %}

Interact

Once a HyperlaneApp implementation is defined, it can be instantiated using the output generated from the HyperlaneAppDeployer and an instance of the MultiProvider.

const chainToContracts = await myDeployer.deploy();
const app = new mydApp(chainToContracts, multiProvider);

To interact with contracts on a particular network, simply provide the namespace to the app.

const ethereumContracts = myApp.getContracts('ethereum');