Contracts
Last updated
Last updated
Returns the Contract Application Binary Interface ( ABI ) of a verified smart contract.
Find verified contracts on our Verified Contracts Source Code page.
https://api-moonriver.moonscan.io/api
?module=contract
&action=getabi
&address=0x01C5291520000a1B977693591065C76576420BB8
&apikey=YourApiKeyToken
Try this endpoint in your browser
Query Parameters
Parameter | Description |
---|---|
Sample Response
{
"status": "1",
"message": "OK-Missing/Invalid API Key, rate limit of 1/5sec applied",
"result": "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_lzEndpoint\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_reason\",\"type\":\"bytes\"}],\"name\":\"MessageFailed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"_payloadHash\",\"type\":\"bytes32\"}],\"name\":\"RetryMessageSuccess\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_type\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_minDstGas\",\"type\":\"uint256\"}],\"name\":\"SetMinDstGas\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"precrime\",\"type\":\"address\"}],\"name\":\"SetPrecrime\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_path\",\"type\":\"bytes\"}],\"name\":\"SetTrustedRemote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_remoteAddress\",\"type\":\"bytes\"}],\"name\":\"SetTrustedRemoteAddress\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_PAYLOAD_SIZE_LIMIT\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"name\":\"failedMessages\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"}],\"name\":\"forceResumeReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_chainId\",\"type\":\"uint16\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_configType\",\"type\":\"uint256\"}],\"name\":\"getConfig\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"}],\"name\":\"getTrustedRemoteAddress\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"}],\"name\":\"isTrustedRemote\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"lastMessage\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lzEndpoint\",\"outputs\":[{\"internalType\":\"contract ILayerZeroEndpoint\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"lzReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"minDstGasLookup\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"nonblockingLzReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"payloadSizeLimitLookup\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"precrime\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"retryMessage\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"message\",\"type\":\"string\"},{\"internalType\":\"uint16\",\"name\":\"destChainId\",\"type\":\"uint16\"}],\"name\":\"sendMessage\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_chainId\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_configType\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_config\",\"type\":\"bytes\"}],\"name\":\"setConfig\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_packetType\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_minGas\",\"type\":\"uint256\"}],\"name\":\"setMinDstGas\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_size\",\"type\":\"uint256\"}],\"name\":\"setPayloadSizeLimit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_precrime\",\"type\":\"address\"}],\"name\":\"setPrecrime\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"}],\"name\":\"setReceiveVersion\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"}],\"name\":\"setSendVersion\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_path\",\"type\":\"bytes\"}],\"name\":\"setTrustedRemote\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_remoteAddress\",\"type\":\"bytes\"}],\"name\":\"setTrustedRemoteAddress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"trustedRemoteLookup\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]"
}
A simple sample for retrieving the contractABI using Web3.js and Jquery to interact with a contract.
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider());
var version = web3.version.api;
$.getJSON('https://api-moonriver.moonscan.io/api?module=contract&action=getabi&address=0x1f1727E2C83c23faE3b1CdB048146647b3B6d17d&apikey=YourApiKeyToken', function (data) {
var contractABI = "";
contractABI = JSON.parse(data.result);
if (contractABI != ''){
var MyContract = web3.eth.contract(contractABI);
var myContractInstance = MyContract.at("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359");
var result = myContractInstance.memberId("0xfe8ad7dd2f564a877cc23feea6c0a9cc2e783715");
console.log("result1 : " + result);
var result = myContractInstance.members(1);
console.log("result2 : " + result);
} else {
console.log("Error" );
}
});
Returns the Solidity source code of a verified smart contract.
https://api-moonriver.moonscan.io/api
?module=contract
&action=getsourcecode
&address=0x01C5291520000a1B977693591065C76576420BB8
&apikey=YourApiKeyToken
Query Parameters
Sample Response
{
"status": "1",
"message": "OK-Missing/Invalid API Key, rate limit of 1/5sec applied",
"result": [
{
"SourceCode": "// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/util/ExcessivelySafeCall.sol\r\n\r\n\r\npragma solidity >=0.7.6;\r\n\r\nlibrary ExcessivelySafeCall {\r\n uint256 constant LOW_28_MASK =\r\n 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;\r\n\r\n /// @notice Use when you _really_ really _really_ don't trust the called\r\n /// contract. This prevents the called contract from causing reversion of\r\n /// the caller in as many ways as we can.\r\n /// @dev The main difference between this and a solidity low-level call is\r\n /// that we limit the number of bytes that the callee can cause to be\r\n /// copied to caller memory. This prevents stupid things like malicious\r\n /// contracts returning 10,000,000 bytes causing a local OOG when copying\r\n /// to memory.\r\n /// @param _target The address to call\r\n /// @param _gas The amount of gas to forward to the remote contract\r\n /// @param _maxCopy The maximum number of bytes of returndata to copy\r\n /// to memory.\r\n /// @param _calldata The data to send to the remote contract\r\n /// @return success and returndata, as `.call()`. Returndata is capped to\r\n /// `_maxCopy` bytes.\r\n function excessivelySafeCall(\r\n address _target,\r\n uint256 _gas,\r\n uint16 _maxCopy,\r\n bytes memory _calldata\r\n ) internal returns (bool, bytes memory) {\r\n // set up for assembly call\r\n uint256 _toCopy;\r\n bool _success;\r\n bytes memory _returnData = new bytes(_maxCopy);\r\n // dispatch message to recipient\r\n // by assembly calling \"handle\" function\r\n // we call via assembly to avoid memcopying a very large returndata\r\n // returned by a malicious contract\r\n assembly {\r\n _success := call(\r\n _gas, // gas\r\n _target, // recipient\r\n 0, // ether value\r\n add(_calldata, 0x20), // inloc\r\n mload(_calldata), // inlen\r\n 0, // outloc\r\n 0 // outlen\r\n )\r\n // limit our copy to 256 bytes\r\n _toCopy := returndatasize()\r\n if gt(_toCopy, _maxCopy) {\r\n _toCopy := _maxCopy\r\n }\r\n // Store the length of the copied bytes\r\n mstore(_returnData, _toCopy)\r\n // copy the bytes from returndata[0:_toCopy]\r\n returndatacopy(add(_returnData, 0x20), 0, _toCopy)\r\n }\r\n return (_success, _returnData);\r\n }\r\n\r\n /// @notice Use when you _really_ really _really_ don't trust the called\r\n /// contract. This prevents the called contract from causing reversion of\r\n /// the caller in as many ways as we can.\r\n /// @dev The main difference between this and a solidity low-level call is\r\n /// that we limit the number of bytes that the callee can cause to be\r\n /// copied to caller memory. This prevents stupid things like malicious\r\n /// contracts returning 10,000,000 bytes causing a local OOG when copying\r\n /// to memory.\r\n /// @param _target The address to call\r\n /// @param _gas The amount of gas to forward to the remote contract\r\n /// @param _maxCopy The maximum number of bytes of returndata to copy\r\n /// to memory.\r\n /// @param _calldata The data to send to the remote contract\r\n /// @return success and returndata, as `.call()`. Returndata is capped to\r\n /// `_maxCopy` bytes.\r\n function excessivelySafeStaticCall(\r\n address _target,\r\n uint256 _gas,\r\n uint16 _maxCopy,\r\n bytes memory _calldata\r\n ) internal view returns (bool, bytes memory) {\r\n // set up for assembly call\r\n uint256 _toCopy;\r\n bool _success;\r\n bytes memory _returnData = new bytes(_maxCopy);\r\n // dispatch message to recipient\r\n // by assembly calling \"handle\" function\r\n // we call via assembly to avoid memcopying a very large returndata\r\n // returned by a malicious contract\r\n assembly {\r\n _success := staticcall(\r\n _gas, // gas\r\n _target, // recipient\r\n add(_calldata, 0x20), // inloc\r\n mload(_calldata), // inlen\r\n 0, // outloc\r\n 0 // outlen\r\n )\r\n // limit our copy to 256 bytes\r\n _toCopy := returndatasize()\r\n if gt(_toCopy, _maxCopy) {\r\n _toCopy := _maxCopy\r\n }\r\n // Store the length of the copied bytes\r\n mstore(_returnData, _toCopy)\r\n // copy the bytes from returndata[0:_toCopy]\r\n returndatacopy(add(_returnData, 0x20), 0, _toCopy)\r\n }\r\n return (_success, _returnData);\r\n }\r\n\r\n /**\r\n * @notice Swaps function selectors in encoded contract calls\r\n * @dev Allows reuse of encoded calldata for functions with identical\r\n * argument types but different names. It simply swaps out the first 4 bytes\r\n * for the new selector. This function modifies memory in place, and should\r\n * only be used with caution.\r\n * @param _newSelector The new 4-byte selector\r\n * @param _buf The encoded contract args\r\n */\r\n function swapSelector(bytes4 _newSelector, bytes memory _buf)\r\n internal\r\n pure\r\n {\r\n require(_buf.length >= 4);\r\n uint256 _mask = LOW_28_MASK;\r\n assembly {\r\n // load the first word of\r\n let _word := mload(add(_buf, 0x20))\r\n // mask out the top 4 bytes\r\n // /x\r\n _word := and(_word, _mask)\r\n _word := or(_newSelector, _word)\r\n mstore(add(_buf, 0x20), _word)\r\n }\r\n }\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/util/BytesLib.sol\r\n\r\n\r\n/*\r\n * @title Solidity Bytes Arrays Utils\r\n * @author Gonçalo Sá <goncalo.sa@consensys.net>\r\n *\r\n * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.\r\n * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.\r\n */\r\npragma solidity >=0.8.0 <0.9.0;\r\n\r\n\r\nlibrary BytesLib {\r\n function concat(\r\n bytes memory _preBytes,\r\n bytes memory _postBytes\r\n )\r\n internal\r\n pure\r\n returns (bytes memory)\r\n {\r\n bytes memory tempBytes;\r\n\r\n assembly {\r\n // Get a location of some free memory and store it in tempBytes as\r\n // Solidity does for memory variables.\r\n tempBytes := mload(0x40)\r\n\r\n // Store the length of the first bytes array at the beginning of\r\n // the memory for tempBytes.\r\n let length := mload(_preBytes)\r\n mstore(tempBytes, length)\r\n\r\n // Maintain a memory counter for the current write location in the\r\n // temp bytes array by adding the 32 bytes for the array length to\r\n // the starting location.\r\n let mc := add(tempBytes, 0x20)\r\n // Stop copying when the memory counter reaches the length of the\r\n // first bytes array.\r\n let end := add(mc, length)\r\n\r\n for {\r\n // Initialize a copy counter to the start of the _preBytes data,\r\n // 32 bytes into its memory.\r\n let cc := add(_preBytes, 0x20)\r\n } lt(mc, end) {\r\n // Increase both counters by 32 bytes each iteration.\r\n mc := add(mc, 0x20)\r\n cc := add(cc, 0x20)\r\n } {\r\n // Write the _preBytes data into the tempBytes memory 32 bytes\r\n // at a time.\r\n mstore(mc, mload(cc))\r\n }\r\n\r\n // Add the length of _postBytes to the current length of tempBytes\r\n // and store it as the new length in the first 32 bytes of the\r\n // tempBytes memory.\r\n length := mload(_postBytes)\r\n mstore(tempBytes, add(length, mload(tempBytes)))\r\n\r\n // Move the memory counter back from a multiple of 0x20 to the\r\n // actual end of the _preBytes data.\r\n mc := end\r\n // Stop copying when the memory counter reaches the new combined\r\n // length of the arrays.\r\n end := add(mc, length)\r\n\r\n for {\r\n let cc := add(_postBytes, 0x20)\r\n } lt(mc, end) {\r\n mc := add(mc, 0x20)\r\n cc := add(cc, 0x20)\r\n } {\r\n mstore(mc, mload(cc))\r\n }\r\n\r\n // Update the free-memory pointer by padding our last write location\r\n // to 32 bytes: add 31 bytes to the end of tempBytes to move to the\r\n // next 32 byte block, then round down to the nearest multiple of\r\n // 32. If the sum of the length of the two arrays is zero then add\r\n // one before rounding down to leave a blank 32 bytes (the length block with 0).\r\n mstore(0x40, and(\r\n add(add(end, iszero(add(length, mload(_preBytes)))), 31),\r\n not(31) // Round down to the nearest 32 bytes.\r\n ))\r\n }\r\n\r\n return tempBytes;\r\n }\r\n\r\n function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {\r\n assembly {\r\n // Read the first 32 bytes of _preBytes storage, which is the length\r\n // of the array. (We don't need to use the offset into the slot\r\n // because arrays use the entire slot.)\r\n let fslot := sload(_preBytes.slot)\r\n // Arrays of 31 bytes or less have an even value in their slot,\r\n // while longer arrays have an odd value. The actual length is\r\n // the slot divided by two for odd values, and the lowest order\r\n // byte divided by two for even values.\r\n // If the slot is even, bitwise and the slot with 255 and divide by\r\n // two to get the length. If the slot is odd, bitwise and the slot\r\n // with -1 and divide by two.\r\n let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)\r\n let mlength := mload(_postBytes)\r\n let newlength := add(slength, mlength)\r\n // slength can contain both the length and contents of the array\r\n // if length < 32 bytes so let's prepare for that\r\n // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage\r\n switch add(lt(slength, 32), lt(newlength, 32))\r\n case 2 {\r\n // Since the new array still fits in the slot, we just need to\r\n // update the contents of the slot.\r\n // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length\r\n sstore(\r\n _preBytes.slot,\r\n // all the modifications to the slot are inside this\r\n // next block\r\n add(\r\n // we can just add to the slot contents because the\r\n // bytes we want to change are the LSBs\r\n fslot,\r\n add(\r\n mul(\r\n div(\r\n // load the bytes from memory\r\n mload(add(_postBytes, 0x20)),\r\n // zero all bytes to the right\r\n exp(0x100, sub(32, mlength))\r\n ),\r\n // and now shift left the number of bytes to\r\n // leave space for the length in the slot\r\n exp(0x100, sub(32, newlength))\r\n ),\r\n // increase length by the double of the memory\r\n // bytes length\r\n mul(mlength, 2)\r\n )\r\n )\r\n )\r\n }\r\n case 1 {\r\n // The stored value fits in the slot, but the combined value\r\n // will exceed it.\r\n // get the keccak hash to get the contents of the array\r\n mstore(0x0, _preBytes.slot)\r\n let sc := add(keccak256(0x0, 0x20), div(slength, 32))\r\n\r\n // save new length\r\n sstore(_preBytes.slot, add(mul(newlength, 2), 1))\r\n\r\n // The contents of the _postBytes array start 32 bytes into\r\n // the structure. Our first read should obtain the `submod`\r\n // bytes that can fit into the unused space in the last word\r\n // of the stored array. To get this, we read 32 bytes starting\r\n // from `submod`, so the data we read overlaps with the array\r\n // contents by `submod` bytes. Masking the lowest-order\r\n // `submod` bytes allows us to add that value directly to the\r\n // stored value.\r\n\r\n let submod := sub(32, slength)\r\n let mc := add(_postBytes, submod)\r\n let end := add(_postBytes, mlength)\r\n let mask := sub(exp(0x100, submod), 1)\r\n\r\n sstore(\r\n sc,\r\n add(\r\n and(\r\n fslot,\r\n 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00\r\n ),\r\n and(mload(mc), mask)\r\n )\r\n )\r\n\r\n for {\r\n mc := add(mc, 0x20)\r\n sc := add(sc, 1)\r\n } lt(mc, end) {\r\n sc := add(sc, 1)\r\n mc := add(mc, 0x20)\r\n } {\r\n sstore(sc, mload(mc))\r\n }\r\n\r\n mask := exp(0x100, sub(mc, end))\r\n\r\n sstore(sc, mul(div(mload(mc), mask), mask))\r\n }\r\n default {\r\n // get the keccak hash to get the contents of the array\r\n mstore(0x0, _preBytes.slot)\r\n // Start copying to the last used word of the stored array.\r\n let sc := add(keccak256(0x0, 0x20), div(slength, 32))\r\n\r\n // save new length\r\n sstore(_preBytes.slot, add(mul(newlength, 2), 1))\r\n\r\n // Copy over the first `submod` bytes of the new data as in\r\n // case 1 above.\r\n let slengthmod := mod(slength, 32)\r\n let mlengthmod := mod(mlength, 32)\r\n let submod := sub(32, slengthmod)\r\n let mc := add(_postBytes, submod)\r\n let end := add(_postBytes, mlength)\r\n let mask := sub(exp(0x100, submod), 1)\r\n\r\n sstore(sc, add(sload(sc), and(mload(mc), mask)))\r\n\r\n for {\r\n sc := add(sc, 1)\r\n mc := add(mc, 0x20)\r\n } lt(mc, end) {\r\n sc := add(sc, 1)\r\n mc := add(mc, 0x20)\r\n } {\r\n sstore(sc, mload(mc))\r\n }\r\n\r\n mask := exp(0x100, sub(mc, end))\r\n\r\n sstore(sc, mul(div(mload(mc), mask), mask))\r\n }\r\n }\r\n }\r\n\r\n function slice(\r\n bytes memory _bytes,\r\n uint256 _start,\r\n uint256 _length\r\n )\r\n internal\r\n pure\r\n returns (bytes memory)\r\n {\r\n require(_length + 31 >= _length, \"slice_overflow\");\r\n require(_bytes.length >= _start + _length, \"slice_outOfBounds\");\r\n\r\n bytes memory tempBytes;\r\n\r\n assembly {\r\n switch iszero(_length)\r\n case 0 {\r\n // Get a location of some free memory and store it in tempBytes as\r\n // Solidity does for memory variables.\r\n tempBytes := mload(0x40)\r\n\r\n // The first word of the slice result is potentially a partial\r\n // word read from the original array. To read it, we calculate\r\n // the length of that partial word and start copying that many\r\n // bytes into the array. The first word we copy will start with\r\n // data we don't care about, but the last `lengthmod` bytes will\r\n // land at the beginning of the contents of the new array. When\r\n // we're done copying, we overwrite the full first word with\r\n // the actual length of the slice.\r\n let lengthmod := and(_length, 31)\r\n\r\n // The multiplication in the next line is necessary\r\n // because when slicing multiples of 32 bytes (lengthmod == 0)\r\n // the following copy loop was copying the origin's length\r\n // and then ending prematurely not copying everything it should.\r\n let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))\r\n let end := add(mc, _length)\r\n\r\n for {\r\n // The multiplication in the next line has the same exact purpose\r\n // as the one above.\r\n let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)\r\n } lt(mc, end) {\r\n mc := add(mc, 0x20)\r\n cc := add(cc, 0x20)\r\n } {\r\n mstore(mc, mload(cc))\r\n }\r\n\r\n mstore(tempBytes, _length)\r\n\r\n //update free-memory pointer\r\n //allocating the array padded to 32 bytes like the compiler does now\r\n mstore(0x40, and(add(mc, 31), not(31)))\r\n }\r\n //if we want a zero-length slice let's just return a zero-length array\r\n default {\r\n tempBytes := mload(0x40)\r\n //zero out the 32 bytes slice we are about to return\r\n //we need to do it because Solidity does not garbage collect\r\n mstore(tempBytes, 0)\r\n\r\n mstore(0x40, add(tempBytes, 0x20))\r\n }\r\n }\r\n\r\n return tempBytes;\r\n }\r\n\r\n function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {\r\n require(_bytes.length >= _start + 20, \"toAddress_outOfBounds\");\r\n address tempAddress;\r\n\r\n assembly {\r\n tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)\r\n }\r\n\r\n return tempAddress;\r\n }\r\n\r\n function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {\r\n require(_bytes.length >= _start + 1 , \"toUint8_outOfBounds\");\r\n uint8 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x1), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {\r\n require(_bytes.length >= _start + 2, \"toUint16_outOfBounds\");\r\n uint16 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x2), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {\r\n require(_bytes.length >= _start + 4, \"toUint32_outOfBounds\");\r\n uint32 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x4), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {\r\n require(_bytes.length >= _start + 8, \"toUint64_outOfBounds\");\r\n uint64 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x8), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {\r\n require(_bytes.length >= _start + 12, \"toUint96_outOfBounds\");\r\n uint96 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0xc), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {\r\n require(_bytes.length >= _start + 16, \"toUint128_outOfBounds\");\r\n uint128 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x10), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {\r\n require(_bytes.length >= _start + 32, \"toUint256_outOfBounds\");\r\n uint256 tempUint;\r\n\r\n assembly {\r\n tempUint := mload(add(add(_bytes, 0x20), _start))\r\n }\r\n\r\n return tempUint;\r\n }\r\n\r\n function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {\r\n require(_bytes.length >= _start + 32, \"toBytes32_outOfBounds\");\r\n bytes32 tempBytes32;\r\n\r\n assembly {\r\n tempBytes32 := mload(add(add(_bytes, 0x20), _start))\r\n }\r\n\r\n return tempBytes32;\r\n }\r\n\r\n function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {\r\n bool success = true;\r\n\r\n assembly {\r\n let length := mload(_preBytes)\r\n\r\n // if lengths don't match the arrays are not equal\r\n switch eq(length, mload(_postBytes))\r\n case 1 {\r\n // cb is a circuit breaker in the for loop since there's\r\n // no said feature for inline assembly loops\r\n // cb = 1 - don't breaker\r\n // cb = 0 - break\r\n let cb := 1\r\n\r\n let mc := add(_preBytes, 0x20)\r\n let end := add(mc, length)\r\n\r\n for {\r\n let cc := add(_postBytes, 0x20)\r\n // the next line is the loop condition:\r\n // while(uint256(mc < end) + cb == 2)\r\n } eq(add(lt(mc, end), cb), 2) {\r\n mc := add(mc, 0x20)\r\n cc := add(cc, 0x20)\r\n } {\r\n // if any of these checks fails then arrays are not equal\r\n if iszero(eq(mload(mc), mload(cc))) {\r\n // unsuccess:\r\n success := 0\r\n cb := 0\r\n }\r\n }\r\n }\r\n default {\r\n // unsuccess:\r\n success := 0\r\n }\r\n }\r\n\r\n return success;\r\n }\r\n\r\n function equalStorage(\r\n bytes storage _preBytes,\r\n bytes memory _postBytes\r\n )\r\n internal\r\n view\r\n returns (bool)\r\n {\r\n bool success = true;\r\n\r\n assembly {\r\n // we know _preBytes_offset is 0\r\n let fslot := sload(_preBytes.slot)\r\n // Decode the length of the stored array like in concatStorage().\r\n let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)\r\n let mlength := mload(_postBytes)\r\n\r\n // if lengths don't match the arrays are not equal\r\n switch eq(slength, mlength)\r\n case 1 {\r\n // slength can contain both the length and contents of the array\r\n // if length < 32 bytes so let's prepare for that\r\n // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage\r\n if iszero(iszero(slength)) {\r\n switch lt(slength, 32)\r\n case 1 {\r\n // blank the last byte which is the length\r\n fslot := mul(div(fslot, 0x100), 0x100)\r\n\r\n if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {\r\n // unsuccess:\r\n success := 0\r\n }\r\n }\r\n default {\r\n // cb is a circuit breaker in the for loop since there's\r\n // no said feature for inline assembly loops\r\n // cb = 1 - don't breaker\r\n // cb = 0 - break\r\n let cb := 1\r\n\r\n // get the keccak hash to get the contents of the array\r\n mstore(0x0, _preBytes.slot)\r\n let sc := keccak256(0x0, 0x20)\r\n\r\n let mc := add(_postBytes, 0x20)\r\n let end := add(mc, mlength)\r\n\r\n // the next line is the loop condition:\r\n // while(uint256(mc < end) + cb == 2)\r\n for {} eq(add(lt(mc, end), cb), 2) {\r\n sc := add(sc, 1)\r\n mc := add(mc, 0x20)\r\n } {\r\n if iszero(eq(sload(sc), mload(mc))) {\r\n // unsuccess:\r\n success := 0\r\n cb := 0\r\n }\r\n }\r\n }\r\n }\r\n }\r\n default {\r\n // unsuccess:\r\n success := 0\r\n }\r\n }\r\n\r\n return success;\r\n }\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/interfaces/ILayerZeroUserApplicationConfig.sol\r\n\r\n\r\n\r\npragma solidity >=0.5.0;\r\n\r\ninterface ILayerZeroUserApplicationConfig {\r\n // @notice set the configuration of the LayerZero messaging library of the specified version\r\n // @param _version - messaging library version\r\n // @param _chainId - the chainId for the pending config change\r\n // @param _configType - type of configuration. every messaging library has its own convention.\r\n // @param _config - configuration in the bytes. can encode arbitrary content.\r\n function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external;\r\n\r\n // @notice set the send() LayerZero messaging library version to _version\r\n // @param _version - new messaging library version\r\n function setSendVersion(uint16 _version) external;\r\n\r\n // @notice set the lzReceive() LayerZero messaging library version to _version\r\n // @param _version - new messaging library version\r\n function setReceiveVersion(uint16 _version) external;\r\n\r\n // @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload\r\n // @param _srcChainId - the chainId of the source chain\r\n // @param _srcAddress - the contract address of the source contract at the source chain\r\n function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external;\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/interfaces/ILayerZeroEndpoint.sol\r\n\r\n\r\n\r\npragma solidity >=0.5.0;\r\n\r\n\r\ninterface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig {\r\n // @notice send a LayerZero message to the specified address at a LayerZero endpoint.\r\n // @param _dstChainId - the destination chain identifier\r\n // @param _destination - the address on destination chain (in bytes). address length/format may vary by chains\r\n // @param _payload - a custom bytes payload to send to the destination contract\r\n // @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address\r\n // @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction\r\n // @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination\r\n function send(uint16 _dstChainId, bytes calldata _destination, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes calldata _adapterParams) external payable;\r\n\r\n // @notice used by the messaging library to publish verified payload\r\n // @param _srcChainId - the source chain identifier\r\n // @param _srcAddress - the source contract (as bytes) at the source chain\r\n // @param _dstAddress - the address on destination chain\r\n // @param _nonce - the unbound message ordering nonce\r\n // @param _gasLimit - the gas limit for external contract execution\r\n // @param _payload - verified payload to send to the destination contract\r\n function receivePayload(uint16 _srcChainId, bytes calldata _srcAddress, address _dstAddress, uint64 _nonce, uint _gasLimit, bytes calldata _payload) external;\r\n\r\n // @notice get the inboundNonce of a lzApp from a source chain which could be EVM or non-EVM chain\r\n // @param _srcChainId - the source chain identifier\r\n // @param _srcAddress - the source chain contract address\r\n function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64);\r\n\r\n // @notice get the outboundNonce from this source chain which, consequently, is always an EVM\r\n // @param _srcAddress - the source chain contract address\r\n function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64);\r\n\r\n // @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery\r\n // @param _dstChainId - the destination chain identifier\r\n // @param _userApplication - the user app address on this EVM chain\r\n // @param _payload - the custom message to send over LayerZero\r\n // @param _payInZRO - if false, user app pays the protocol fee in native token\r\n // @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain\r\n function estimateFees(uint16 _dstChainId, address _userApplication, bytes calldata _payload, bool _payInZRO, bytes calldata _adapterParam) external view returns (uint nativeFee, uint zroFee);\r\n\r\n // @notice get this Endpoint's immutable source identifier\r\n function getChainId() external view returns (uint16);\r\n\r\n // @notice the interface to retry failed message on this Endpoint destination\r\n // @param _srcChainId - the source chain identifier\r\n // @param _srcAddress - the source chain contract address\r\n // @param _payload - the payload to be retried\r\n function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external;\r\n\r\n // @notice query if any STORED payload (message blocking) at the endpoint.\r\n // @param _srcChainId - the source chain identifier\r\n // @param _srcAddress - the source chain contract address\r\n function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);\r\n\r\n // @notice query if the _libraryAddress is valid for sending msgs.\r\n // @param _userApplication - the user app address on this EVM chain\r\n function getSendLibraryAddress(address _userApplication) external view returns (address);\r\n\r\n // @notice query if the _libraryAddress is valid for receiving msgs.\r\n // @param _userApplication - the user app address on this EVM chain\r\n function getReceiveLibraryAddress(address _userApplication) external view returns (address);\r\n\r\n // @notice query if the non-reentrancy guard for send() is on\r\n // @return true if the guard is on. false otherwise\r\n function isSendingPayload() external view returns (bool);\r\n\r\n // @notice query if the non-reentrancy guard for receive() is on\r\n // @return true if the guard is on. false otherwise\r\n function isReceivingPayload() external view returns (bool);\r\n\r\n // @notice get the configuration of the LayerZero messaging library of the specified version\r\n // @param _version - messaging library version\r\n // @param _chainId - the chainId for the pending config change\r\n // @param _userApplication - the contract address of the user application\r\n // @param _configType - type of configuration. every messaging library has its own convention.\r\n function getConfig(uint16 _version, uint16 _chainId, address _userApplication, uint _configType) external view returns (bytes memory);\r\n\r\n // @notice get the send() LayerZero messaging library version\r\n // @param _userApplication - the contract address of the user application\r\n function getSendVersion(address _userApplication) external view returns (uint16);\r\n\r\n // @notice get the lzReceive() LayerZero messaging library version\r\n // @param _userApplication - the contract address of the user application\r\n function getReceiveVersion(address _userApplication) external view returns (uint16);\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/interfaces/ILayerZeroReceiver.sol\r\n\r\n\r\n\r\npragma solidity >=0.5.0;\r\n\r\ninterface ILayerZeroReceiver {\r\n // @notice LayerZero endpoint will invoke this function to deliver the message on the destination\r\n // @param _srcChainId - the source endpoint identifier\r\n // @param _srcAddress - the source sending contract address from the source chain\r\n // @param _nonce - the ordered message nonce\r\n // @param _payload - the signed payload is the UA bytes has encoded to be sent\r\n function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) external;\r\n}\r\n\r\n// File: @openzeppelin/contracts/utils/Context.sol\r\n\r\n\r\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n/**\r\n * @dev Provides information about the current execution context, including the\r\n * sender of the transaction and its data. While these are generally available\r\n * via msg.sender and msg.data, they should not be accessed in such a direct\r\n * manner, since when dealing with meta-transactions the account sending and\r\n * paying for execution may not be the actual sender (as far as an application\r\n * is concerned).\r\n *\r\n * This contract is only required for intermediate, library-like contracts.\r\n */\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n\r\n function _msgData() internal view virtual returns (bytes calldata) {\r\n return msg.data;\r\n }\r\n}\r\n\r\n// File: @openzeppelin/contracts/access/Ownable.sol\r\n\r\n\r\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\r\n\r\npragma solidity ^0.8.0;\r\n\r\n\r\n/**\r\n * @dev Contract module which provides a basic access control mechanism, where\r\n * there is an account (an owner) that can be granted exclusive access to\r\n * specific functions.\r\n *\r\n * By default, the owner account will be the one that deploys the contract. This\r\n * can later be changed with {transferOwnership}.\r\n *\r\n * This module is used through inheritance. It will make available the modifier\r\n * `onlyOwner`, which can be applied to your functions to restrict their use to\r\n * the owner.\r\n */\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n /**\r\n * @dev Initializes the contract setting the deployer as the initial owner.\r\n */\r\n constructor() {\r\n _transferOwnership(_msgSender());\r\n }\r\n\r\n /**\r\n * @dev Throws if called by any account other than the owner.\r\n */\r\n modifier onlyOwner() {\r\n _checkOwner();\r\n _;\r\n }\r\n\r\n /**\r\n * @dev Returns the address of the current owner.\r\n */\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n\r\n /**\r\n * @dev Throws if the sender is not the owner.\r\n */\r\n function _checkOwner() internal view virtual {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n }\r\n\r\n /**\r\n * @dev Leaves the contract without owner. It will not be possible to call\r\n * `onlyOwner` functions. Can only be called by the current owner.\r\n *\r\n * NOTE: Renouncing ownership will leave the contract without an owner,\r\n * thereby disabling any functionality that is only available to the owner.\r\n */\r\n function renounceOwnership() public virtual onlyOwner {\r\n _transferOwnership(address(0));\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Can only be called by the current owner.\r\n */\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n _transferOwnership(newOwner);\r\n }\r\n\r\n /**\r\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\r\n * Internal function without access restriction.\r\n */\r\n function _transferOwnership(address newOwner) internal virtual {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/lzApp/LzApp.sol\r\n\r\n\r\n\r\npragma solidity ^0.8.0;\r\n\r\n\r\n\r\n\r\n\r\n\r\n/*\r\n * a generic LzReceiver implementation\r\n */\r\nabstract contract LzApp is Ownable, ILayerZeroReceiver, ILayerZeroUserApplicationConfig {\r\n using BytesLib for bytes;\r\n\r\n // ua can not send payload larger than this by default, but it can be changed by the ua owner\r\n uint constant public DEFAULT_PAYLOAD_SIZE_LIMIT = 10000;\r\n\r\n ILayerZeroEndpoint public immutable lzEndpoint;\r\n mapping(uint16 => bytes) public trustedRemoteLookup;\r\n mapping(uint16 => mapping(uint16 => uint)) public minDstGasLookup;\r\n mapping(uint16 => uint) public payloadSizeLimitLookup;\r\n address public precrime;\r\n\r\n event SetPrecrime(address precrime);\r\n event SetTrustedRemote(uint16 _remoteChainId, bytes _path);\r\n event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress);\r\n event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint _minDstGas);\r\n\r\n constructor(address _endpoint) {\r\n lzEndpoint = ILayerZeroEndpoint(_endpoint);\r\n }\r\n\r\n function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual override {\r\n // lzReceive must be called by the endpoint for security\r\n require(_msgSender() == address(lzEndpoint), \"LzApp: invalid endpoint caller\");\r\n\r\n bytes memory trustedRemote = trustedRemoteLookup[_srcChainId];\r\n // if will still block the message pathway from (srcChainId, srcAddress). should not receive message from untrusted remote.\r\n require(_srcAddress.length == trustedRemote.length && trustedRemote.length > 0 && keccak256(_srcAddress) == keccak256(trustedRemote), \"LzApp: invalid source sending contract\");\r\n\r\n _blockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\r\n }\r\n\r\n // abstract function - the default behaviour of LayerZero is blocking. See: NonblockingLzApp if you dont need to enforce ordered messaging\r\n function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual;\r\n\r\n function _lzSend(uint16 _dstChainId, bytes memory _payload, address payable _refundAddress, address _zroPaymentAddress, bytes memory _adapterParams, uint _nativeFee) internal virtual {\r\n bytes memory trustedRemote = trustedRemoteLookup[_dstChainId];\r\n require(trustedRemote.length != 0, \"LzApp: destination chain is not a trusted source\");\r\n _checkPayloadSize(_dstChainId, _payload.length);\r\n lzEndpoint.send{value: _nativeFee}(_dstChainId, trustedRemote, _payload, _refundAddress, _zroPaymentAddress, _adapterParams);\r\n }\r\n\r\n function _checkGasLimit(uint16 _dstChainId, uint16 _type, bytes memory _adapterParams, uint _extraGas) internal view virtual {\r\n uint providedGasLimit = _getGasLimit(_adapterParams);\r\n uint minGasLimit = minDstGasLookup[_dstChainId][_type] + _extraGas;\r\n require(minGasLimit > 0, \"LzApp: minGasLimit not set\");\r\n require(providedGasLimit >= minGasLimit, \"LzApp: gas limit is too low\");\r\n }\r\n\r\n function _getGasLimit(bytes memory _adapterParams) internal pure virtual returns (uint gasLimit) {\r\n require(_adapterParams.length >= 34, \"LzApp: invalid adapterParams\");\r\n assembly {\r\n gasLimit := mload(add(_adapterParams, 34))\r\n }\r\n }\r\n\r\n function _checkPayloadSize(uint16 _dstChainId, uint _payloadSize) internal view virtual {\r\n uint payloadSizeLimit = payloadSizeLimitLookup[_dstChainId];\r\n if (payloadSizeLimit == 0) { // use default if not set\r\n payloadSizeLimit = DEFAULT_PAYLOAD_SIZE_LIMIT;\r\n }\r\n require(_payloadSize <= payloadSizeLimit, \"LzApp: payload size is too large\");\r\n }\r\n\r\n //---------------------------UserApplication config----------------------------------------\r\n function getConfig(uint16 _version, uint16 _chainId, address, uint _configType) external view returns (bytes memory) {\r\n return lzEndpoint.getConfig(_version, _chainId, address(this), _configType);\r\n }\r\n\r\n // generic config for LayerZero user Application\r\n function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external override onlyOwner {\r\n lzEndpoint.setConfig(_version, _chainId, _configType, _config);\r\n }\r\n\r\n function setSendVersion(uint16 _version) external override onlyOwner {\r\n lzEndpoint.setSendVersion(_version);\r\n }\r\n\r\n function setReceiveVersion(uint16 _version) external override onlyOwner {\r\n lzEndpoint.setReceiveVersion(_version);\r\n }\r\n\r\n function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external override onlyOwner {\r\n lzEndpoint.forceResumeReceive(_srcChainId, _srcAddress);\r\n }\r\n\r\n // _path = abi.encodePacked(remoteAddress, localAddress)\r\n // this function set the trusted path for the cross-chain communication\r\n function setTrustedRemote(uint16 _remoteChainId, bytes calldata _path) external onlyOwner {\r\n trustedRemoteLookup[_remoteChainId] = _path;\r\n emit SetTrustedRemote(_remoteChainId, _path);\r\n }\r\n\r\n function setTrustedRemoteAddress(uint16 _remoteChainId, bytes calldata _remoteAddress) external onlyOwner {\r\n trustedRemoteLookup[_remoteChainId] = abi.encodePacked(_remoteAddress, address(this));\r\n emit SetTrustedRemoteAddress(_remoteChainId, _remoteAddress);\r\n }\r\n\r\n function getTrustedRemoteAddress(uint16 _remoteChainId) external view returns (bytes memory) {\r\n bytes memory path = trustedRemoteLookup[_remoteChainId];\r\n require(path.length != 0, \"LzApp: no trusted path record\");\r\n return path.slice(0, path.length - 20); // the last 20 bytes should be address(this)\r\n }\r\n\r\n function setPrecrime(address _precrime) external onlyOwner {\r\n precrime = _precrime;\r\n emit SetPrecrime(_precrime);\r\n }\r\n\r\n function setMinDstGas(uint16 _dstChainId, uint16 _packetType, uint _minGas) external onlyOwner {\r\n require(_minGas > 0, \"LzApp: invalid minGas\");\r\n minDstGasLookup[_dstChainId][_packetType] = _minGas;\r\n emit SetMinDstGas(_dstChainId, _packetType, _minGas);\r\n }\r\n\r\n // if the size is 0, it means default size limit\r\n function setPayloadSizeLimit(uint16 _dstChainId, uint _size) external onlyOwner {\r\n payloadSizeLimitLookup[_dstChainId] = _size;\r\n }\r\n\r\n //--------------------------- VIEW FUNCTION ----------------------------------------\r\n function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool) {\r\n bytes memory trustedSource = trustedRemoteLookup[_srcChainId];\r\n return keccak256(trustedSource) == keccak256(_srcAddress);\r\n }\r\n}\r\n\r\n// File: https://github.com/LayerZero-Labs/solidity-examples/blob/main/contracts/lzApp/NonblockingLzApp.sol\r\n\r\n\r\n\r\npragma solidity ^0.8.0;\r\n\r\n\r\n\r\n/*\r\n * the default LayerZero messaging behaviour is blocking, i.e. any failed message will block the channel\r\n * this abstract class try-catch all fail messages and store locally for future retry. hence, non-blocking\r\n * NOTE: if the srcAddress is not configured properly, it will still block the message pathway from (srcChainId, srcAddress)\r\n */\r\nabstract contract NonblockingLzApp is LzApp {\r\n using ExcessivelySafeCall for address;\r\n\r\n constructor(address _endpoint) LzApp(_endpoint) {}\r\n\r\n mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;\r\n\r\n event MessageFailed(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload, bytes _reason);\r\n event RetryMessageSuccess(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes32 _payloadHash);\r\n\r\n // overriding the virtual function in LzReceiver\r\n function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual override {\r\n (bool success, bytes memory reason) = address(this).excessivelySafeCall(gasleft(), 150, abi.encodeWithSelector(this.nonblockingLzReceive.selector, _srcChainId, _srcAddress, _nonce, _payload));\r\n // try-catch all errors/exceptions\r\n if (!success) {\r\n _storeFailedMessage(_srcChainId, _srcAddress, _nonce, _payload, reason);\r\n }\r\n }\r\n\r\n function _storeFailedMessage(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload, bytes memory _reason) internal virtual {\r\n failedMessages[_srcChainId][_srcAddress][_nonce] = keccak256(_payload);\r\n emit MessageFailed(_srcChainId, _srcAddress, _nonce, _payload, _reason);\r\n }\r\n\r\n function nonblockingLzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual {\r\n // only internal transaction\r\n require(_msgSender() == address(this), \"NonblockingLzApp: caller must be LzApp\");\r\n _nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\r\n }\r\n\r\n //@notice override this function\r\n function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual;\r\n\r\n function retryMessage(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public payable virtual {\r\n // assert there is message to retry\r\n bytes32 payloadHash = failedMessages[_srcChainId][_srcAddress][_nonce];\r\n require(payloadHash != bytes32(0), \"NonblockingLzApp: no stored message\");\r\n require(keccak256(_payload) == payloadHash, \"NonblockingLzApp: invalid payload\");\r\n // clear the stored message\r\n failedMessages[_srcChainId][_srcAddress][_nonce] = bytes32(0);\r\n // execute the message. revert if it fails again\r\n _nonblockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload);\r\n emit RetryMessageSuccess(_srcChainId, _srcAddress, _nonce, payloadHash);\r\n }\r\n}\r\n\r\n// File: gist-54b79e3a5b95605c298edaf2f23614cd/SimpleGeneralMessage.sol\r\n\r\n\r\npragma solidity ^0.8.12;\r\n\r\n\r\ncontract SimpleGeneralMessage is NonblockingLzApp {\r\n using BytesLib for bytes;\r\n\r\n uint dummy = 0; // This is useless, and is just so that the deployed bytecode will be different\r\n\r\n mapping(address => string) public lastMessage;\r\n\r\n constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint) {}\r\n\r\n function _nonblockingLzReceive(uint16, bytes memory, uint64, bytes memory _payload) override internal {\r\n (address sender, string memory message) = abi.decode(_payload, (address, string));\r\n lastMessage[sender] = message;\r\n }\r\n\r\n function sendMessage(string memory message, uint16 destChainId) external payable {\r\n bytes memory payload = abi.encode(msg.sender, message);\r\n _lzSend({\r\n _dstChainId: destChainId, \r\n _payload: payload, \r\n _refundAddress: payable(msg.sender), \r\n _zroPaymentAddress: address(0x0), \r\n _adapterParams: bytes(\"\"), \r\n _nativeFee: msg.value}\r\n );\r\n }\r\n}",
"ABI": "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_lzEndpoint\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_reason\",\"type\":\"bytes\"}],\"name\":\"MessageFailed\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"_payloadHash\",\"type\":\"bytes32\"}],\"name\":\"RetryMessageSuccess\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_type\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"_minDstGas\",\"type\":\"uint256\"}],\"name\":\"SetMinDstGas\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"address\",\"name\":\"precrime\",\"type\":\"address\"}],\"name\":\"SetPrecrime\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_path\",\"type\":\"bytes\"}],\"name\":\"SetTrustedRemote\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"indexed\":false,\"internalType\":\"bytes\",\"name\":\"_remoteAddress\",\"type\":\"bytes\"}],\"name\":\"SetTrustedRemoteAddress\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"DEFAULT_PAYLOAD_SIZE_LIMIT\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"\",\"type\":\"uint64\"}],\"name\":\"failedMessages\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"}],\"name\":\"forceResumeReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_chainId\",\"type\":\"uint16\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_configType\",\"type\":\"uint256\"}],\"name\":\"getConfig\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"}],\"name\":\"getTrustedRemoteAddress\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"}],\"name\":\"isTrustedRemote\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"name\":\"lastMessage\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"lzEndpoint\",\"outputs\":[{\"internalType\":\"contract ILayerZeroEndpoint\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"lzReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"minDstGasLookup\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"nonblockingLzReceive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"payloadSizeLimitLookup\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"precrime\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_srcChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_srcAddress\",\"type\":\"bytes\"},{\"internalType\":\"uint64\",\"name\":\"_nonce\",\"type\":\"uint64\"},{\"internalType\":\"bytes\",\"name\":\"_payload\",\"type\":\"bytes\"}],\"name\":\"retryMessage\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"message\",\"type\":\"string\"},{\"internalType\":\"uint16\",\"name\":\"destChainId\",\"type\":\"uint16\"}],\"name\":\"sendMessage\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_chainId\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_configType\",\"type\":\"uint256\"},{\"internalType\":\"bytes\",\"name\":\"_config\",\"type\":\"bytes\"}],\"name\":\"setConfig\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"internalType\":\"uint16\",\"name\":\"_packetType\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_minGas\",\"type\":\"uint256\"}],\"name\":\"setMinDstGas\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_dstChainId\",\"type\":\"uint16\"},{\"internalType\":\"uint256\",\"name\":\"_size\",\"type\":\"uint256\"}],\"name\":\"setPayloadSizeLimit\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_precrime\",\"type\":\"address\"}],\"name\":\"setPrecrime\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"}],\"name\":\"setReceiveVersion\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_version\",\"type\":\"uint16\"}],\"name\":\"setSendVersion\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_path\",\"type\":\"bytes\"}],\"name\":\"setTrustedRemote\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"_remoteChainId\",\"type\":\"uint16\"},{\"internalType\":\"bytes\",\"name\":\"_remoteAddress\",\"type\":\"bytes\"}],\"name\":\"setTrustedRemoteAddress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint16\",\"name\":\"\",\"type\":\"uint16\"}],\"name\":\"trustedRemoteLookup\",\"outputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
"ContractName": "SimpleGeneralMessage",
"CompilerVersion": "v0.8.12+commit.f00d7308",
"OptimizationUsed": "0",
"Runs": "200",
"ConstructorArguments": "0000000000000000000000007004396c99d5690da76a7c59057c5f3a53e01704",
"EVMVersion": "Default",
"Library": "",
"LicenseType": "None",
"Proxy": "0",
"Implementation": "",
"SwarmSource": "ipfs://215b639d334fe332028afc7cee08fcc0e8a6a120b72431d7c31c15da328e81bd"
}
]
}
Submits a contract source code to Moonscan for verification.
Requires a valid Moonscan API key, it will be rejected otherwise
Only supports HTTP POST due to max transfer size limitations for HTTP GET
Supports up to 10 different library pairs
Contracts that use "imports" will need to have the code concatenated into one file as we do not support "imports" in separate files.
List of supported solc versions, only solc version v0.4.11 and above is supported e.g. v0.4.25+commit.59dbf8f1
Upon successful submission you will receive a GUID (50 characters) as a receipt
You may use this GUID to track the status of your submission
Verified Source Codes will be displayed at the Verified Contracts page.
//Submit Source Code for Verification
$.ajax({
type: "POST", //Only POST supported
url: "//api-moonriver.moonscan.io/api", //Set to the correct API url for Other Networks
data: {
apikey: $('#apikey').val(), //A valid API-Key is required
module: 'contract', //Do not change
action: 'verifysourcecode', //Do not change
contractaddress: $('#contractaddress').val(), //Contract Address starts with 0x...
sourceCode: $('#sourceCode').val(), //Contract Source Code (Flattened if necessary)
codeformat: $('#codeformat').val(), //solidity-single-file (default) or solidity-standard-json-input (for std-input-json-format support
contractname: $('#contractname').val(), //ContractName (if codeformat=solidity-standard-json-input, then enter contractname as ex: erc20.sol:erc20)
compilerversion: $('#compilerversion').val(), // see https://moonriver.moonscan.io/solcversions for list of support versions
optimizationUsed: $('#optimizationUsed').val(), //0 = No Optimization, 1 = Optimization used (applicable when codeformat=solidity-single-file)
runs: 200, //set to 200 as default unless otherwise (applicable when codeformat=solidity-single-file)
constructorArguements: $('#constructorArguements').val(), //if applicable
evmversion: $('#evmVersion').val(), //leave blank for compiler default, homestead, tangerineWhistle, spuriousDragon, byzantium, constantinople, petersburg, istanbul (applicable when codeformat=solidity-single-file)
licenseType: $('#licenseType').val(), //Valid codes 1-12 where 1=No License .. 12=Apache 2.0, see https://moonriver.moonscan.io/contract-license-types
libraryname1: $('#libraryname1').val(), //if applicable, a matching pair with libraryaddress1 required
libraryaddress1: $('#libraryaddress1').val(), //if applicable, a matching pair with libraryname1 required
libraryname2: $('#libraryname2').val(), //if applicable, matching pair required
libraryaddress2: $('#libraryaddress2').val(), //if applicable, matching pair required
libraryname3: $('#libraryname3').val(), //if applicable, matching pair required
libraryaddress3: $('#libraryaddress3').val(), //if applicable, matching pair required
libraryname4: $('#libraryname4').val(), //if applicable, matching pair required
libraryaddress4: $('#libraryaddress4').val(), //if applicable, matching pair required
libraryname5: $('#libraryname5').val(), //if applicable, matching pair required
libraryaddress5: $('#libraryaddress5').val(), //if applicable, matching pair required
libraryname6: $('#libraryname6').val(), //if applicable, matching pair required
libraryaddress6: $('#libraryaddress6').val(), //if applicable, matching pair required
libraryname7: $('#libraryname7').val(), //if applicable, matching pair required
libraryaddress7: $('#libraryaddress7').val(), //if applicable, matching pair required
libraryname8: $('#libraryname8').val(), //if applicable, matching pair required
libraryaddress8: $('#libraryaddress8').val(), //if applicable, matching pair required
libraryname9: $('#libraryname9').val(), //if applicable, matching pair required
libraryaddress9: $('#libraryaddress9').val(), //if applicable, matching pair required
libraryname10: $('#libraryname10').val(), //if applicable, matching pair required
libraryaddress10: $('#libraryaddress10').val() //if applicable, matching pair required
},
success: function (result) {
console.log(result);
if (result.status == "1") {
//1 = submission success, use the guid returned (result.result) to check the status of your submission.
// Average time of processing is 30-60 seconds
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
// result.result is the GUID receipt for the submission, you can use this guid for checking the verification status
} else {
//0 = error
document.getElementById("postresult").innerHTML = result.status + ";" + result.message + ";" + result.result;
}
console.log("status : " + result.status);
console.log("result : " + result.result);
},
error: function (result) {
console.log("error!");
document.getElementById("postresult").innerHTML = "Unexpected Error"
}
});
//Check Source Code Verification Status
$.ajax({
type: "GET",
url: "//api-moonriver.moonscan.io/api",
data: {
apikey: $('#apikey').val(),
guid: 'ezq878u486pzijkvvmerl6a9mzwhv6sefgvqi5tkwceejc7tvn', //Replace with your Source Code GUID receipt above
module: "contract",
action: "checkverifystatus"
},
success: function (result) {
console.log("status : " + result.status); //0=Error, 1=Pass
console.log("message : " + result.message); //OK, NOTOK
console.log("result : " + result.result); //result explanation
$('#guidstatus').html(">> " + result.result);
},
error: function (result) {
alert('error');
}
});
Submits a proxy contract source code to Moonscan for verification.
Requires a valid Moonscan API key, it will be rejected otherwise
Current daily limit of 100 submissions per day per user (subject to change)
Only supports HTTP post
Upon successful submission you will receive a GUID (50 characters) as a receipt
You may use this GUID to track the status of your submission
Verified proxy contracts will display the "Read/Write as Proxy" of the implementation contract under the contract address's contract tab
// example with only the mandatory contract address parameter
curl -d "address=0xcbdcd3815b5f975e1a2c944a9b2cd1c985a1cb7f" "https://api-moonriver.moonscan.io/api?module=contract&action=verifyproxycontract&apikey=YourApiKeyToken"
// example using the expectedimplementation optional parameter
// the expectedimplementation enforces a check to ensure the returned implementation contract address == address picked up by the verifier
curl -d "address=0xbc46363a7669f6e12353fa95bb067aead3675c29&expectedimplementation=0xe45a5176bc0f2c1198e2451c4e4501d4ed9b65a6" "https://api-moonriver.moonscan.io/api?module=contract&action=verifyproxycontract&apikey=YourApiKeyToken"
// OK
{"status":"1","message":"OK","result":"gwgrrnfy56zf6vc1fljuejwg6pelnc5yns6fg6y2i6zfpgzquz"}
// NOTOK
{"status":"0","message":"NOTOK","result":"Invalid API Key"}
curl "https://api-moonriver.moonscan.io/api?module=contract&action=checkproxyverification&guid=gwgrrnfy56zf6vc1fljuejwg6pelnc5yns6fg6y2i6zfpgzquz&apikey=YourApiKeyToken"
// OK
{"status":"1","message":"OK","result":"The proxy's (0xbc46363a7669f6e12353fa95bb067aead3675c29) implementation contract is found at 0xe45a5176bc0f2c1198e2451c4e4501d4ed9b65a6 and is successfully updated."}
// NOTOK
{"status":"0","message":"NOTOK","result":"A corresponding implementation contract was unfortunately not detected for the proxy address."}
Tip : You can also download a CSV list of verified contracts addresses of which the code publishers have provided a corresponding Open Source license for redistribution.
Try this endpoint in your browser
Parameter | Description |
---|---|
Note : This endpoint is limited to 100 verifications/day, regardless of API PRO tier.
Note: Upon successful submission, a GUID is returned, which can be used to check for submission status.
address
the contract address
that has a verified source code
address
the contract address
that has a verified source code