relevant tag icon
LayerZero OmniCounter Example
copy icon
LayerZero
• version 1.0.0
Communication
Protocol
Crosschain
Example
Audited

LayerZero OmniCounter Example

Audited

LayerZero example contract for cross chain communication. OmniCounter is a contract that increments a counter - -but there's a twist. This OmniCounter increments the counter on another chain.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

LayerZero

Recent Use

🍞 0x775F downloaded

Last Publish

11/25/2022
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
getCounter() :
This function is a public view function that returns the current value of the messageCounter variable. This variable is used to keep track of the number of messages sent to the contract. The function simply returns the current value of the messageCounter variable. (autogenerated documentation)
lzReceive(uint16,,uint64,) :
This function is an override of the lzReceive function in the LazyLedger contract. It is used to receive payloads from an endpoint. It takes in four parameters: a uint16, a bytes memory _fromAddress, a uint64, and a bytes memory _payload. The function first checks that the sender of the message is the same as the address of the endpoint. It then loads the address from the _fromAddress parameter and stores it in the fromAddress variable. Next, the function checks if the keccak256 hash of the _payload parameter is equal to the keccak256 hash of the bytes10("ff"). If it is, the endpoint.re (autogenerated documentation)
incrementCounter(uint16) :
This function is used to increment a counter on a destination chain. It takes two parameters: a uint16 _dstChainId, which is the ID of the destination chain, and a bytes calldata _dstCounterMockAddress, which is the address of the counter mock contract on the destination chain. The function then sends a message to the endpoint contract, with the sender address, the value of the message, and the destination chain ID and counter mock address as parameters. If the payInZRO flag is set to true, the payment address is set to the address of the contract, otherwise it is set to 0x0. (autogenerated documentation)
incrementCounterWithPayload(uint16) :
This function is used to increment a counter on a destination chain. It takes in a destination chain ID, a destination counter mock address, and a payload as parameters. It then sends a message to the endpoint with the value of the message, the destination chain ID, the destination counter mock address, the sender address, a zero payment address, and an empty string. This message is used to increment the counter on the destination chain. (autogenerated documentation)
incrementCounterWithAdapterParamsV1(uint16) :
This function is used to increment a counter on a destination chain. It takes in three parameters: the destination chain ID, the address of the counter mock on the destination chain, and the amount of gas to be used for the transaction on the destination chain. It then encodes these parameters into a bytes array and sends them to the endpoint contract, along with the sender's address and a value (in this case, the amount of Ether sent with the transaction). The endpoint contract will then use the parameters to execute the transaction on the destination chain. (autogenerated documentation)
incrementCounterWithAdapterParamsV2(uint16,address) :
This function is used to increment a counter on a destination chain using an adapter. It takes in the destination chain ID, the address of the counter mock on the destination chain, the amount of gas to be used for the destination chain, the amount of ETH to be airdropped, and the address to which the ETH should be airdropped. It then encodes the version, gas amount, airdrop ETH quantity, and airdrop address into a bytes array, and sends this array along with the sender address, a zero address, and the value of the message to the endpoint. The endpoint then uses this data to increment the counter on the destination chain. (autogenerated documentation)
incrementCounterMulti(uint16[],address) :
This function is used to increment a counter on multiple chains. It takes in two arrays, one containing the chain IDs of the destination chains and the other containing the addresses of the counter mocks on those chains. It also takes in an address for the refund. The function then divides the value sent with the transaction by the number of chains and sends that amount to each of the destination chains. Finally, it transfers any remaining amount to the refund address. (autogenerated documentation)
setConfig(uint16,,uint16) :
This function allows a user to set a configuration for a specific chain ID. The configuration is specified by the _configType parameter and the _config parameter contains the data for the configuration. The function calls the setConfig() function of the endpoint contract, passing in the address of the current contract, the chain ID, the configuration type, and the configuration data. (autogenerated documentation)
getConfig(uint16,,uint16) :
This function is used to retrieve a configuration from a given endpoint. It takes in two uint16 values (chainId and configType), an address, and returns a bytes memory value. The function calls the getConfig() function from the endpoint, passing in the endpoint's send version, the chainId, the address of the contract, and the configType. The getConfig() function then returns the configuration as a bytes memory value. (autogenerated documentation)
setSendVersion(uint16) :
This function sets the version of the endpoint that will be used when sending messages. It works by calling the setSendVersion() function on the endpoint object, passing in the version number as an argument. (autogenerated documentation)
setReceiveVersion(uint16) :
This function sets the version of the receive protocol for the endpoint. It works by calling the setReceiveVersion() function on the endpoint, passing in the version number as an argument. This function is typically used to ensure that the endpoint is using the most up-to-date version of the receive protocol. (autogenerated documentation)
getSendVersion() :
This function retrieves the version of the endpoint associated with the current contract. It does this by calling the getSendVersion() function from the endpoint contract, passing in the address of the current contract as an argument. The function returns a uint16 value representing the version of the endpoint. (autogenerated documentation)
getReceiveVersion() :
This function gets the version of the contract that is currently being received by the contract. It works by calling the getReceiveVersion() function from the endpoint contract, passing in the address of the current contract as an argument. The function then returns the version of the contract that is currently being received. (autogenerated documentation)
setOracle(uint16,address) :
This function sets the oracle address for a given destination chain ID. It does this by calling the setConfig() function of the endpoint contract, passing in the send version of the current contract, the destination chain ID, the type of configuration (in this case, 6 for oracle), and the oracle address encoded using the ABI. The setConfig() function then stores the oracle address in the endpoint contract. (autogenerated documentation)
setInboundConfirmations(uint16,uint16) :
This function sets the number of confirmations required for inbound transactions on a given remote chain. It takes two parameters, the remote chain ID and the number of confirmations required. It then calls the setConfig() function on the endpoint contract, passing in the send version of the current contract, the remote chain ID, the type of configuration (2 for inbound confirmations) and the number of confirmations required, encoded as an ABI. (autogenerated documentation)
setOutboundConfirmations(uint16,uint16) :
This function sets the number of outbound confirmations required for a given remote chain. It does this by calling the setConfig() function of the endpoint contract, passing in the send version of the current contract, the remote chain ID, the type of configuration (5 for outbound confirmations), and the number of confirmations as an encoded parameter. (autogenerated documentation)
forceResumeReceive(uint16) :
This function is used to force a resume of a receive operation on a given source chain and address. It works by allowing the caller to specify the source chain ID and address of the receive operation they wish to resume. The function then checks the validity of the parameters and resumes the receive operation. (autogenerated documentation)
setPayInZRO(bool) :
This function allows the owner of the contract to set a boolean value that determines whether payments are made in ZRO tokens or not. If the value is set to true, payments will be made in ZRO tokens. If the value is set to false, payments will not be made in ZRO tokens. (autogenerated documentation)
approveTokenSpender(address,address) :
This function allows the owner of a token contract to approve a spender to spend a certain amount of the token. It does this by calling the IERC20 approve function, which sets an allowance for the spender to spend the specified amount of the token. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i layerzero-omnicounter
copy icon

Recent Use

🍞 0x775F downloaded

Last Publish

11/25/2022

Version

1.0.0

Creator

LayerZero

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.