Encode a cross-chain swap
POST /api/v1/swap
Cross-chain swaps on Meson use compact encoding to compress data. This API will accept human-readable parameters in the request body and return an encoded swap.
- application/json
Request Body required
- from string (chain:token) required
The initial chain and token type. See supported chains.
- to string (chain:token) required
The target chain and token type. See supported chains.
- amount string_of_number required
Amount of tokens to initialize the cross-chain swap.
- fromAddress address required
The address on initial chain to initialize the cross-chain swap.
- recipient address required
The address on target chain to receive cross-chain'ed assets.
- dataToContract hex_string_8_bytes
A hex string of 8 bytes (e.g.
0x00000000000000000000
). IfdataToContract
is present, the cross-chain'ed fund will be released to a smart contract by calling the methoddepositWithBeneficiary
. Please ensure that therecipient
is a smart contract that has implemented this method. Failure to do so may result in the funds becoming stuck. See an example here.
- 200
- 400
Successful operation
- application/json
- Schema
- Example (from schema)
- For Mainnet
- For Testnet
Schema
result object
encoded hex_string_32_bytesThe encoded swap data which will be used in the next API
fromAddress addressSame as
fromAddress
in the request bodyrecipient addressSame as
recipient
in the request bodyinitiator addressA parameter used to call the Meson smart contract. Always an eth address. See usage instructions
fee object
Fee data of this swap
serviceFee string_of_numberFee charged by Meson protocol
lpFee string_of_numberFee charged by liquidity providers on Meson
totalFee string_of_numberTotal fee to be charged
converted optional
For some swap routes (i.e.
arb:usdc
->merlin:btc
) token conversion is allowed.amount string_of_numberAmount of converted token to receive
token stringConverted token
signingRequest object
Present if
fromAddress
is an externally owned address (EOA). Thehash
to be signed before submitting a cross-chain swap through the next API.message hex_stringhash hex_string_32_bytestx object
Present if the swap originates from an EVM-compatible chain and represents the transaction data required to interact with the Meson smart contract. Note that if the swap involves ERC-20 tokens, you must first call
approve
on the token contract to grant sufficient allowance totx.to
before submitting this transaction.to addressMeson contract address
value string_of_numberAmount of the chain's native token (typically ETH) that must be sent with the transaction
data hex_stringABI-encoded payload including the contract method and parameters
{
"result": {
"encoded": "string",
"fromAddress": "string",
"recipient": "string",
"initiator": "string",
"fee": {
"serviceFee": "string",
"lpFee": "string",
"totalFee": "string"
},
"converted": {
"amount": "string",
"token": "string"
},
"signingRequest": {
"message": "string",
"hash": "string"
},
"tx": {
"to": "string",
"value": "string",
"data": "string"
}
}
}
Please note that the `hash` in `signingRequest` needs to be signed before submitting a cross-chain swap through the next API.
{
"result": {
"encoded": "0x010000989680d8000000000018740e1f000000138800640554a003c60202ca21",
"fromAddress": "0x243f22fbd4c375581aaacfcfff5a43793eb8a74d",
"recipient": "0xa9af0380e43516ce889e2df136e6e1e451dbb488",
"fee": {
"serviceFee": "0",
"lpFee": "0.005",
"totalFee": "0.005"
},
"signingRequest": {
"message": "0x19457468657265756d205369676e6564204d6573736167653a0a3532010000989680d8000000000018740e1f000000138800640554a003c60202ca21a9af0380e43516ce889e2df136e6e1e451dbb488",
"hash": "0x230ca80a4ac53ec051ea63a2dd8d5cbb15a27c866629d08c38bf1607b09346df"
}
}
}
Please note that the `hash` in `signingRequest` needs to be signed before submitting a cross-chain swap through the next API.
{
"result": {
"encoded": "0x010000989680d80000000000cb13cba8000000000000644325ec02ca2236a721",
"fromAddress": "0x2eF8a51F8fF129DBb874A0efB021702F59C1b211",
"recipient": "0x2eF8a51F8fF129DBb874A0efB021702F59C1b211",
"fee": {
"serviceFee": "0",
"lpFee": "0",
"totalFee": "0"
},
"signingRequest": {
"message": "0x19457468657265756d205369676e6564204d6573736167653a0a3532010000989680d80000000000cb13cba8000000000000644325ec02ca2236a7212ef8a51f8ff129dbb874a0efb021702f59c1b211",
"hash": "0x654b084de8320e96eb6645711f59260054bcbef2d885b151c91d20451831a5f2"
}
}
}
Error
- application/json
- Schema
- Example (from schema)
Schema
error object
code int32message stringdata object
code string
{
"error": {
"code": -1,
"message": "[error_message]",
"data": {
"code": "[error_code]"
}
}
}