Skip to content

Commit 2470e99

Browse files
Merge pull request #352 from etherlinkcom/gelato-example
Simple example of using Gelato to automate contracts
2 parents 76bc3b9 + bc0adce commit 2470e99

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

docs/tools/cross-chain-comms.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ title: Cross chain communication
77
[LayerZero](https://layerzero.network/) is an interoperability protocol that connects blockchains, allowing developers to build seamless omnichain applications, tokens, and experiences.
88

99
Learn more about sending messages across chains [here](https://docs.layerzero.network/v2/developers/evm/getting-started), and find the endpoint addresses already deployed [here](https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts).
10+
11+
## Gelato
12+
13+
You can also use Gelato Web3 Functions to communicate across chains; see [Gelato](/tools/developer-experience#gelato).

docs/tools/developer-experience.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,65 @@ It also helps manage transactions that are waiting for signatures.
1919

2020
Gelato Web3 Functions supports Etherlink, which lets you automate Etherlink contracts based on off-chain activity and activity on other chains.
2121
For more information, see the Gelato Web3 Functions documentation at https://docs.gelato.cloud/Web3-Functions/Introduction/Overview.
22+
23+
For example, this contract emits an event when its `sayMarco` function is called:
24+
25+
```solidity
26+
// SPDX-License-Identifier: UNLICENSED
27+
pragma solidity ^0.8.13;
28+
29+
contract Marco {
30+
event MarcoEvent(address indexed caller);
31+
32+
function sayMarco() public {
33+
emit MarcoEvent(msg.sender);
34+
}
35+
}
36+
```
37+
38+
Similarly, this contract has a `hearMarco` function that emits an event when it is called:
39+
40+
```solidity
41+
// SPDX-License-Identifier: UNLICENSED
42+
pragma solidity ^0.8.13;
43+
44+
contract Polo {
45+
event PoloEvent(address indexed caller);
46+
47+
uint256 timesHeard;
48+
49+
constructor() {
50+
timesHeard = 0;
51+
}
52+
53+
function hearMarco() public {
54+
timesHeard += 1;
55+
emit PoloEvent(msg.sender);
56+
}
57+
58+
function getTimesHeard() external view returns (uint256) {
59+
return timesHeard;
60+
}
61+
}
62+
```
63+
64+
Because smart contracts cannot respond to events, these two contracts cannot interact directly.
65+
You can use Gelato Web3 Functions to listen for the `Marco` event and call the `hearMarco` function, even if these two contracts are on different networks.
66+
67+
For example, you can register with Gelato at https://app.gelato.cloud and then click **Functions** and **New** to create a new function.
68+
69+
On the New Function Task window, select the trigger, in this case **On-chain Event**.
70+
Gelato also supports time and block-based triggers.
71+
72+
Select the network to monitor (such as Etherlink Testnet or Mainnet), specify the address and ABI of the contract, and the event to trigger on, as in this screencap:
73+
74+
<img src="/img/gelato-trigger.png" alt="Setting the trigger condition for the Web3 Function" style={{width: 300}} />
75+
76+
Then, further down, specify the action to run when the trigger happens.
77+
For example, to call the other contract's `hearMarco` function, click **Transaction**.
78+
Then, select the network and specify the address, ABI, and function to call, as in this screencap:
79+
80+
<img src="/img/gelato-transaction.png" alt="Setting the transaction to run when the trigger happens" style={{width: 300}} />
81+
82+
Now when the first contract emits the event, Gelato calls the second contract.
83+
These contracts can be on the same chain or different chains.

static/img/gelato-transaction.png

248 KB
Loading

static/img/gelato-trigger.png

218 KB
Loading

0 commit comments

Comments
 (0)