Created
October 29, 2023 01:53
-
-
Save crazilazi/5b17c11eef6000a2d47aff124cb59009 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.22+commit.4fc1097e.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.17; | |
import "https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/lzApp/NonblockingLzApp.sol"; | |
contract ChitChat is NonblockingLzApp { | |
string public message = "Initial message"; | |
constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint) Ownable() {} | |
function _nonblockingLzReceive( | |
uint16, | |
bytes memory, | |
uint64, | |
bytes memory _payload | |
) internal override { | |
message = abi.decode(_payload, (string)); | |
} | |
function sendMessageToDestinationChain(uint16 destChainId, string memory _message) public payable { | |
bytes memory payload = abi.encode(_message); | |
_lzSend( | |
destChainId, | |
payload, | |
payable(msg.sender), | |
address(0x0), | |
bytes(""), | |
msg.value | |
); | |
} | |
function trustAddress( | |
uint16 destChainId, | |
address _otherContract | |
) public onlyOwner { | |
trustedRemoteLookup[destChainId] = abi.encodePacked( | |
_otherContract, | |
address(this) | |
); | |
} | |
function estimateFees( | |
uint16 dstChainId, | |
bytes calldata adapterParams, | |
string memory _message | |
) public view returns (uint256 nativeFee, uint256 zroFee) { | |
bytes memory payload = abi.encode(_message); | |
return | |
lzEndpoint.estimateFees( | |
dstChainId, | |
address(this), | |
payload, | |
false, | |
adapterParams | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment