Loopring Dev Docs
  • Introduction
  • Endpoints
  • SDK
    • SDK Guides
    • Test Mock Data
      • Mock Account
      • Mock provider
      • Mock ERC20 Token Map
      • Mock AMM MAP
      • Mock EIP712 Typed Data
      • Mock Generate eddsaKey
  • Glossary
  • 🗳️Loopring Account
    • Introduction
    • SDK Guides
      • Setup a Loopring Account
      • Unlock Account (Login)
    • API References
      • Get Account info
        • Sample code
      • Update EddsaKey
        • Sample code
      • Get apiKey
        • Sample code
      • Update apiKey
        • Sample code
  • 🎨CounterFactual NFT
    • Introduction
      • Compute NFT Address API
      • When to deploy counterfactual NFT contracts?
    • SDK Guides
      • Deposit NFT
      • Create Collection
      • Mint Counterfactual NFT
      • Transfer NFT
      • Deploy NFT
      • Withdraw NFT
      • Trade NFT
        • Validate NFT Order
      • Meta & IPFS
    • API References
      • NFT Collection
        • Create collection
          • Sample code
        • Edit collection
          • Sample code
        • Delete collection
          • Sample code
        • List owned collections
          • Sample code
        • List user's NFTs under one collection
          • Sample code
        • List user's NFT balances group by Collection ID
          • Sample code
        • List all NFTs of a collection
          • Sample code
        • Get collection by Collection ID
          • Sample code
        • Get collections by contract address
          • Sample code
      • Get NFT Assets
        • Sample code
      • Get NFT Balances
        • Sample code
      • Mint NFT
        • Sample code
      • Transfer NFT
        • Sample code
      • Validate NFT Order
        • Sample code
      • Trade NFT
        • Sample code
      • Deploy NFT TokenAddress
        • Sample code
      • Withdraw NFT
        • Sample code
      • Get NFT Transactions
        • Sample code
      • Get NFT Trade History
        • Sample code
      • Get AvailableBroker
        • Sample code
      • Get NFT Info
        • Sample code
      • Get NFT Data
        • Sample code
      • Get NFT Holders
        • Sample code
  • 🪙ERC20 Tokens
    • Introduction
    • SDK Guides
      • Transfer ERC20
      • Withdraw ERC20
      • Deposit ERC20
      • Order ERC20
    • API References
      • Get Assets
        • Sample code
      • Transfer
        • Sample code
      • Submit Order
        • Sample code
      • Cancel Order
        • Sample code
      • Withdraw
        • Sample code
      • Get Transactions
        • Sample code
      • Get Orders
        • Sample code
      • Get Trade History
        • Sample code
  • 🔬Resources
    • Advanced
      • UpdateAccount with custom seed
      • Pay payee updateAccount fee
      • Common error and solutions
      • Submit erc20 order
    • Common Info
      • Get relayer current time
        • Sample code
      • Get exchange info
        • Sample code
      • Get token info
        • Sample code
      • Get markets info
        • Sample code
    • Error codes
    • Fees
      • GET ERC20 Offchain Fee
        • Sample code
      • GET ERC20 Order Fee
        • Sample code
      • GET NFT Offchain Fee
        • Sample code
      • GET NFT Order Fee
        • Sample code
      • SDK Fees
    • Layer 2 block info
      • Get pending transactions
    • Request signing
      • Special API Request Signatures
      • Off-chain Request Signatures
      • Extra ECDSA authentic in header
    • Signature
      • ECDSA signature
        • ECDSA key generation
        • ECDSA sign
        • ECDSA verify signature
      • EdDSA signature
        • EdDSA key generation
        • EdDSA sign
        • EdDSA verify signature
      • SDK Signature
        • Mock Signature
    • Smart Contracts
    • Storage Id
      • Sample code
    • WebSocket
      • Account Notification
      • Order Notification
      • Orderbook Notification
      • Trade Notification
      • Ticker Notification
      • Candlestick Notification
      • AMM Pool Snapshot Notification
      • Block Generation Notification
    • Loopring Smart Wallet
      • Signature and verification
Powered by GitBook
On this page
  • EndPoint
  • Header
  • Request
  • Response
  • Model
  • TokenVolume
  • counterFactualInfo
  • Compute ECDSA hash
  • Compute EdDSA hash

Was this helpful?

  1. ERC20 Tokens
  2. API References

Withdraw

Withdraw ERC20 tokens from your layer2 to address in layer1

EndPoint

POST /api/v3/user/withdrawals 

Header

Field
Description
Example

X-API-KEY

ApiKey

"HlkcGxbqBeaF76j4rvPaOasyfPwnkQ6B6DQ6THZWbvrAGxzEdulXQvOKLrRWZLnN"

X-API-SIG

"0xccf0a141fce2dc5cbbd4f802c52220e9e2ce260e86704d6258603eb346eefe2d 4a450005c362b223b28402d087f7065ea5eee0314531adf6a580fce64c25dca81c02"

Request

Query Param
Description
Example

exchange

owner

account owner address

accountId

account ID

10110

token

to

withdraw to address

maxFee

storageId

1

validUntil

Timestamp for withdraw to become invalid, seconds

normally current time + 2 months

eddsaSignature

minGas

withdraw gas, set to 0 now

0

extraData

set to "" now

""

payPayeeUpdateAccount

true

counterFactualInfo

if it's counterFactual wallet, need 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 withdrawal info

"0x1d923ca783 4dc90484fa2e b611f0f0bc7e 741bb107007e bea19ba8caea b4f9d3"

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 async 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 Info

Field
Description
Example

walletFactory

Counterfactual wallet factory contract address

"0xbbbbca6a90 1c926f240b89 eacb641d8aec 7aeafd"

walletOwner

Counterfactual wallet owner address, NOT the wallet address

"0xbbbbca6a90 1c926f240b89 eacb641d8aec 7aeafd"

walletSalt

Salt to generate address from owner & other related info

"1"

Compute ECDSA hash

const typedData: EIP712TypedData = {
    types: {
      EIP712Domain: [
        { name: "name", type: "string" },
        { name: "version", type: "string" },
        { name: "chainId", type: "uint256" },
        { name: "verifyingContract", type: "address" },
      ],
      Withdrawal: [
        { name: "owner", type: "address" },
        { name: "accountID", type: "uint32" },
        { name: "tokenID", type: "uint16" },
        { name: "amount", type: "uint96" },
        { name: "feeTokenID", type: "uint16" },
        { name: "maxFee", type: "uint96" },
        { name: "to", type: "address" },
        { name: "extraData", type: "bytes" },
        { name: "minGas", type: "uint256" },
        { name: "validUntil", type: "uint32" },
        { name: "storageID", type: "uint32" },
      ],
    },
    primaryType: "Withdrawal",
    domain: {
      name: "Loopring Protocol",
      version: "3.6.0",
      chainId: chainId,
      verifyingContract: data.exchange,
    },
    message: message,
  };

Compute EdDSA hash


const onchainDataHash = abi
    .soliditySHA3(
      ["uint256", "address", "bytes"],
      [
        request.minGas,
        new BN(fm.clearHexPrefix(request.to), 16),
        ethUtil.toBuffer(request.extraData),
      ]
    )
    .slice(0, 20);

const orderHashStr = fm.addHexPrefix(onchainDataHash.toString("hex"));
const inputs = [
    new BN(ethUtil.toBuffer(request.exchange)).toString(),
    request.accountId,
    request.token.tokenId,
    request.token.volume,
    request.maxFee.tokenId,
    request.maxFee.volume,
    orderHashStr,
    request.validUntil,
    request.storageId,
  ];
const hasher = Poseidon.createHash(inputs.length + 1, 6, 53);
const hash = hasher(inputs).toString(10);
PreviousSample codeNextSample code

Last updated 2 years ago

Was this helpful?

, pay attention the signature type, sign the

exchangeAddress in

,withdraw tokenId and volume

from

offchainId of

of the

🪙
exchange info
storage Id
(Optional) transfer to pay payee updateAccount fee
ECDSA Signature
ecdsa hash
tokenVolume
offchain fee
tokenVolume
eddsa signature
eddsa hash
(Optional) counterFactual Wallet Info