L
L
Loopring Dev Docs
Search…
⌃K

Transfer

Sending ERC20 tokens from your Loopring L2 to another Loopring L2 address.

EndPoint

POST api/v3/transfer
Field
Description
Example
X-API-KEY
ApiKey
"HlkcGxbqBeaF76j4rvPaOasyfPwnkQ6B6DQ6THZWbvrGxzEdulXQvOKLrRWZLnN"
X-API-SIG
ECDSA Signature, pay attention the signature type, sign the ecdsa hash
"0xccf0a141fce2dc5cbbd4f802c52220e9e2ce260e86704d6258603eb346eefe2d4a450005c362b223b2842d087f7065ea5eee0314531adf6a580fce64c25dca81c02"

Request

Query Param
Description
Example
exchange
exchangeAddress in exchange info
payerAddr
payer address
payerId
payer account ID
10110
payeeAddr
payee address
payeeId
payee account ID
10111,can set to 0 if dont have
token
tokenVolume,transfer tokenId and volume
maxFee
storageId
offchainId of storage Id, sellTokenId is the transfer tokenId
1
validUntil
Timestamp for transfer to become invalid, seconds
normally current time + 2 months
eddsaSignature
memo
(Optional) memo
payPayeeUpdateAccount
(Optional) transfer to pay payee updateAccount fee , true or false, default is false
true
counterFactualInfo
(Optional) counterfactual Wallet Info, if it's a counterfactual wallet, need to pass the info

Response

Field
Description
Example
hash
The hash identifier set by the user at the time of submission, can use this hash to get the transfer info
"0x1d923ca7834dc90484fa2eb611f0f0bc7e741bb107007ebea19ba8caeab4f9d3"
status
Whether the order was successfully submitted or not, please note, the user may query after a while to get the real process status, as most off-chain requests are asynchronously processed Allowable : ['received', 'processing', 'processed', 'failed']
"received"
isIdempotent
Idempotent of submit transfer response, submit same transfer again idempotent will be true
"false"

Model

TokenVolume

Wrapper object used to describe a token associated with a certain quantity.
Field
Description
Example
tokenId
The Loopring's token identifier.
0
volume
The volume of the token
"100000000000 0"

counterFactualInfo

Counterfactual wallet information.
Field
Description
Example
walletFactory
Counterfactual wallet factory contract address
"0xbbbbca6a901c926f240b89eacb641d8aec7aeafd"
walletOwner
Counterfactual wallet owner address, NOT the wallet address
"0xbbbbca6a901c926f240b89eacb641d8aec7aeafd"
walletSalt
Salt to generate address from owner & other related info
"1"

Compute ecdsa hash

const message = {
from: data.payerAddr,
to: data.payeeAddr,
tokenID: data.token.tokenId,
amount: data.token.volume,
feeTokenID: data.maxFee.tokenId,
maxFee: data.maxFee.volume,
validUntil: data.validUntil,
storageID: data.storageId,
};
const typedData: EIP712TypedData = {
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" },
],
Transfer: [
{ name: "from", type: "address" },
{ name: "to", type: "address" },
{ name: "tokenID", type: "uint16" },
{ name: "amount", type: "uint96" },
{ name: "feeTokenID", type: "uint16" },
{ name: "maxFee", type: "uint96" },
{ name: "validUntil", type: "uint32" },
{ name: "storageID", type: "uint32" },
],
},
primaryType: "Transfer",
domain: {
name: "Loopring Protocol",
version: "3.6.0",
chainId: chainId,
verifyingContract: data.exchange,
},
message: message,
};

Compute eddsa hash

const inputs = [
new BN(ethUtil.toBuffer(request.exchange)).toString(),
request.payerId,
request.payeeId,
request.token.tokenId,
request.token.volume,
request.maxFee.tokenId,
request.maxFee.volume,
new BN(ethUtil.toBuffer(request.payeeAddr)).toString(),
0,
0,
request.validUntil,
request.storageId,
];
const hasher = Poseidon.createHash(inputs.length + 1, 6, 53);
const hash = hasher(inputs).toString(10);

Example

Header

X-API-KEY = l4hd4CGLLGuZ9nEultG4sfhQZDjPp9sv0kMy13cyGgkJyIWDodVSM4S4ucb5WFKN
X-API-SIG = 0x33f9a4fa0c439067e90dcbfc2a0522fee7a18f511c9956824fb2760bba15eb8a349fe76bd7acbf3c7bc165834767f282844b1a680d81cb5b35a45bd7fa8a91c11b02

Request

POST api/v3/transfer
{
"eddsaSignature": "0x210238285d9855c97fb581876021ef3315506c997b79a409256d791d0883bc622e3a441537b893ac6d09e1e5b01f163d72e3ab6c04fad50e66416f23eac8d0f12122818e943171229b7b130b732e39113b71e41be79b4d644b5d76d2208fb749",
"exchange": "0x2e76EBd1c7c0C8e7c2B875b6d505a260C525d25e",
"maxFee": {
"tokenId": 2,
"volume": "97700"
},
"memo": "test",
"payeeAddr": "0x44DDED4865F2640ccC5a5D8F0923ce6E68Aac381",
"payeeId": 0,
"payerAddr": "0x6b1029c9ae8aa5eea9e045e8ba3c93d380d5bdda",
"payerId": 10010,
"storageId": 1021,
"token": {
"tokenId": 0,
"volume": "100000000000000"
},
"validUntil": 1655879465
}

Response

{
"hash": "0x0cd6d70917ce6cf9c9b13a11d14aa3381285c1ab018d357ba043ed08c4bdb672",
"status": "processing",
"isIdempotent": false,
"accountId": 10010,
"tokenId": 0,
"storageId": 1021
}