Last active
June 14, 2023 22:39
-
-
Save jboetticher/54b79e3a5b95605c298edaf2f23614cd to your computer and use it in GitHub Desktop.
A contract that sends and stores a string between chains using LayerZero.
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.12; | |
import "https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/lzApp/NonblockingLzApp.sol"; | |
contract SimpleGeneralMessage is NonblockingLzApp { | |
using BytesLib for bytes; | |
mapping(address => string) public lastMessage; | |
constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint) {} | |
function _nonblockingLzReceive(uint16, bytes memory, uint64, bytes memory _payload) override internal { | |
(address sender, string memory message) = abi.decode(_payload, (address, string)); | |
lastMessage[sender] = message; | |
} | |
function sendMessage(string memory message, uint16 destChainId) external payable { | |
bytes memory payload = abi.encode(msg.sender, message); | |
_lzSend({ | |
_dstChainId: destChainId, | |
_payload: payload, | |
_refundAddress: payable(msg.sender), | |
_zroPaymentAddress: address(0x0), | |
_adapterParams: bytes(""), | |
_nativeFee: msg.value} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment