Skip to content

Instantly share code, notes, and snippets.

@crazilazi
Created October 29, 2023 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crazilazi/5b17c11eef6000a2d47aff124cb59009 to your computer and use it in GitHub Desktop.
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=
// 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