v2
Ask or search…
K

App Abstraction

Interact with your application on multiple chains
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();
}
}
See the Hyperlane Hello World app for an example of how to extend HyperlaneApp.

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');