This repository is an example of using Axelar to do cross-chain calls using interface contracts similar to the ones that Cubist will generate. The example is based on other Axelar examples.
In this simple example, there are two functions (inc() and store(uint256))
in an Ethereum contract (EthCounter) that we call from Avalanche through the
Axelar infrastructure. The contracts that a user would write are
EthCounter.sol (deployed on Ethereum)
and AvaCounter.sol (deployed on
Avalanche).
On the Avalanche side there is an
EthCounter.sol contract that exposes
the cross-chain functions in an interface that corresponds to the contract on
the Ethereum side. The functions on this contract encode the function and
arguments for the cross-chain calls, use the Axelar API to pay for the
cross-chain calls, and then use the API to initiate the call. The cross-chain
function to call is encoded using abi.encodeWithSignature().
On the Ethereum side there is an
EthCounterInterface.sol
contract that acts as the receiving contract for calls from Axelar. To do so,
it overrides the _execute() function and executes the call stored in the
payload on the original
contract.
It then matches the function id and invokes the corresponding function on the
original contract with the decoded arguments.
The deployment of the contracts in this repository has to happen in the following order:
EthCounteron EthereumEthCounterInterfaceon Ethereum (requires the address of (EthCounter)EthCounter(the interface) on Avalanche (requires the address ofEthCounterInterface)AvaCounteron Avalanche (requires the address of theEthCounterinterface)
Build contracts:
npm install
npx hardhat compileStart servers (run command in a different terminal or background):
node scripts/runLocal.jsDeploy contracts:
node scripts/deploy.jsTest contracts/bridging:
node scripts/test.js