Skip to content
Information Circle

The Spanning Demo App is live! Check it out here: https://demo.spanning.network/

We have also published the open-source demo code and related JavaScript utilities.

On-Chain Spanning Requests

Sending messages (including raw data and contract execution requests) across chains is fundamental to any multichain Dapp.

To do so, we can use the makeRequest function of the Spanning Delegate on your current chain. This can be made directly to the Delegate contract from an EOA (Externally Owned Account) or your smart contract.

This function takes in two arguments:

programAddress

The programAddress is the Spanning Address of the contract you want to reach. This can be a contract on the same network or any deployable chain on the Spanning Network. The programAddress' domain information tells the Spanning Network what network to send the request to, the local network address information tells the Spanning Network where to give the request on that network, and the buffer information can include additional routing information (like how many block confirmations to wait before sending the request to the destination chain).

payload

The payload is the encoded ABI function call to execute at the programAddress. This can be any generic function call on any contract.

Example Request

Here is some sample code for how to make a Spanning Request from your smart contract:

ISpanningDelegate delegateContract = ISpanningDelegate(0x1234...) // with your local Delegate address

bytes32 programAddress = SpanningAddress.create(
            0x1234..., // The local contract address on the Fuji Network
            0x0000A869 // This is the Domain ID for the Fuji Network
        );

// Encode `foo(bar, baz)`
bytes memory payload = abi.encodeWithSignature(
            "foo(bool,uint256)", // these can be any argument types
            bar, // the value of the first argument
            baz // the value of the second argument
        );

delegateContract.makeRequest(programAddress, payload);

Here is another example of the same request from your smart contract, but with some routing parameters to specify that the Spanning Network waits for six block confirmations of the requesting chain before executing the request on the destination chain.

ISpanningDelegate delegateContract = ISpanningDelegate(0x1234...) // with your local Delegate address

bytes32 programAddress = SpanningAddress.create(
            0x1234..., // The local contract address on the Fuji Network
            0x0000A869 // This is the Domain ID for the Fuji Network
        );
programAddress = SpaningAddress.packAddressData(
            programAddress,
            6, // the data to pack, in this case a number of block confirmations to wait
            20 // the byte of the Spanning Address to pack, byte 20 is reserved for this parameter
        );

bytes memory payload = abi.encodeWithSignature(
            "foo(bool,uint256)", // these can be any argument types
            bar, // the value of the first argument
            baz // the value of the second argument
        );

delegateContract.makeRequest(programAddress, payload);