Skip to content

Instantly share code, notes, and snippets.

@jboetticher
Last active June 14, 2023 22:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jboetticher/54b79e3a5b95605c298edaf2f23614cd to your computer and use it in GitHub Desktop.
Save jboetticher/54b79e3a5b95605c298edaf2f23614cd to your computer and use it in GitHub Desktop.
A contract that sends and stores a string between chains using LayerZero.
// 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