@@ -57,22 +57,10 @@ A Universal App is a contract that implements the `UniversalContract` interface.
5757// SPDX-License-Identifier: MIT
5858pragma solidity 0.8.26;
5959
60- import "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM .sol";
60+ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/UniversalContract .sol";
6161
6262contract Universal is UniversalContract {
63- GatewayZEVM public immutable gateway;
64-
6563 event HelloEvent(string, string);
66- error Unauthorized();
67-
68- modifier onlyGateway() {
69- if (msg.sender != address(gateway)) revert Unauthorized();
70- _;
71- }
72-
73- constructor(address payable gatewayAddress) {
74- gateway = GatewayZEVM(gatewayAddress);
75- }
7664
7765 function onCall(
7866 MessageContext calldata context,
@@ -86,10 +74,6 @@ contract Universal is UniversalContract {
8674}
8775```
8876
89- The constructor takes ZetaChain’s Gateway address and stores it in a state
90- variable. The Gateway is used for making outbound contract calls and token
91- withdrawals.
92-
9377A universal contract must implement the ` onCall ` function. This function is
9478triggered when the contract receives a call from a connected chain via the
9579Gateway. The function processes incoming data, which includes:
@@ -109,7 +93,8 @@ In this example, `onCall` decodes the message into a string and emits an event.
10993
11094` onCall ` should only be called by the Gateway to ensure that it is only called
11195as a response to a call on a connected chain and that you can trust the values
112- of the function parameters.
96+ of the function parameters. This is enforced by the ` onlyGateway ` modifier,
97+ which is inherited from ` UniversalContract ` .
11398
11499## Option 1: Deploy on Localnet
115100
@@ -160,48 +145,21 @@ The `forge build` command tells Foundry to compile all Solidity smart contracts
160145within your project, ensuring you're working with the latest compiled versions.
161146Successful compilation will generate bytecode for your contracts.
162147
163- To deploy and interact with contracts on the ZetaChain localnet, you'll need the
164- address of the ZetaChain Gateway contract. This contract acts as the entry point
165- for cross-chain interactions on ZetaChain.
166-
167- - While your localnet is still running in its dedicated terminal, carefully
168- examine its output.
169- - Copy the Gateway contract address from the localnet terminal output. Look for
170- the row labeled ` gateway ` under the ` ZETACHAIN ` section. It will typically
171- appear in a format similar to this:
172-
173- ```
174- | gateway │ '0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6' |
175- ```
176-
177- Copy only the hexadecimal address (e.g.,
178- ` 0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6 ` ). Do not include the single quotes
179- or any other surrounding text.
180-
181- Alternatively, run the following command to get the Gateway address
182- programmatically:
183-
184- ```
185- GATEWAY_ZETACHAIN=$(jq -r '.["31337"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ZETACHAIN
186- ```
187-
188148Fetch a private key with pre-funded tokens on the connected chain:
189149
190150```
191151PRIVATE_KEY=$(jq -r '.private_keys[0]' ~/.zetachain/localnet/anvil.json) && echo $PRIVATE_KEY
192152```
193153
194- Deploy the universal contract and provide the Gateway address in the
195- constructor:
154+ Deploy the universal contract:
196155
197156```
198157UNIVERSAL=$(forge create Universal \
199158 --rpc-url http://localhost:8545 \
200159 --private-key $PRIVATE_KEY \
201160 --evm-version paris \
202161 --broadcast \
203- --json \
204- --constructor-args $GATEWAY_ZETACHAIN | jq -r .deployedTo) && echo $UNIVERSAL
162+ --json | jq -r .deployedTo) && echo $UNIVERSAL
205163```
206164
207165### Make a Call to the Universal App
@@ -263,16 +221,14 @@ string.
263221
264222### Deploy the Contract on ZetaChain
265223
266- Deploy the contract to ZetaChain’s testnet using the Gateway address from the
267- [ Contract Addresses page] ( /reference/network/contracts/ ) :
224+ Deploy the contract to ZetaChain’s testnet:
268225
269226```
270227UNIVERSAL=$(forge create Universal \
271228 --rpc-url https://zetachain-athens-evm.blockpi.network/v1/rpc/public \
272229 --private-key $PRIVATE_KEY \
273230 --broadcast \
274- --json \
275- --constructor-args 0x6c533f7fe93fae114d0954697069df33c9b74fd7 | jq -r .deployedTo)
231+ --json | jq -r .deployedTo)
276232```
277233
278234### Call a Universal Contract from Base
0 commit comments