sender.sol 1.1 KB

12345678910111213141516171819202122232425262728
  1. // SPDX-License-Identifier: UNLICENSED
  2. pragma solidity ^0.8.0;
  3. import "@layerzerolabs/solidity-examples/contracts/lzApp/interfaces/ILayerZeroEndpoint.sol";
  4. contract sender {
  5. ILayerZeroEndpoint public endpoint;
  6. constructor(address _endpoint) {
  7. endpoint = ILayerZeroEndpoint(_endpoint);
  8. }
  9. // an endpoint is the contract which has the send() function
  10. function send(address _remoteAddress, uint16 _dstChainId) external payable {
  11. // remote address concated with local address packed into 40 bytes
  12. address localAddress = address(this);
  13. bytes memory remoteAndLocalAddresses = abi.encodePacked(_remoteAddress, localAddress);
  14. // call send() to send a message/payload to another chain
  15. endpoint.send{value: msg.value}(
  16. _dstChainId, // destination LayerZero chainId
  17. remoteAndLocalAddresses, // send to this address on the destination
  18. bytes("hello"), // bytes payload
  19. payable(msg.sender), // refund address
  20. address(0x0), // future parameter
  21. bytes("") // adapterParams (see "Advanced Features")
  22. );
  23. }
  24. }