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

Was this helpful?

  1. Loopring Account
  2. SDK Guides

Setup a Loopring Account

Open an account via the Loopring DEX.

PreviousSDK GuidesNextUnlock Account (Login)

Last updated 2 years ago

Was this helpful?

Please update SDK after v3.1.5 and use UnlockAccount with `account.publicKey or `generateKeyPair` with `account.publicKey`

Step 1: Register a wallet address in the Loopring DEX to get an account ID

There are two ways to register an account on the Loopring DEX to get an account ID:

  1. via API - Make a deposit to your address by calling the . Once the Loopring exchange receives your deposit (8 confirmations), it will generate an account id for your address.

  2. via - Use an account in Loopring Layer 2 to transfer some tokens to your address, after the transfer is successful, this will generate an account id for the payee address.

Step 2: Retrieve account info using by address

Using the newly acquired account id, retrieve the account information using the getAccount call.

const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
  owner: LOOPRING_EXPORTED_ACCOUNT.address,
});
Step 3: Use keySeed or CUSTOMER_KEY_SEED generateKeyPair

Generate an EdDSA key-pair using ecdsa to sign message. An EdDSA key-pair is needed for making changes to an account in the SDK. You can create a key-seed phrase using the default recommendation or a custom value.

  • Default keySeed

    Default keySeed string format we use looks like the following:

Sign this message to access Loopring Exchange: %s with key nonce: %d'.

You will need to replace %s with the , and replace %d with the value of the nonce received in the account information from .

const keySeed = sdk.BaseAPI.KEY_MESSAGE.replace(
      "${exchangeAddress}",
      LOOPRING_EXPORTED_ACCOUNT.exchangeAddress
    ).replace("${nonce}", accInfo.nonce.toString());
const eddsaKey = await sdk.generateKeyPair({
  web3,
  address: accInfo.owner,
  keySeed,
  walletType: sdk.ConnectorNames.MetaMask,
  chainId: sdk.ChainId.GOERLI,
});
console.log("eddsakey:", eddsaKey.sk);
  • Custom keySeed

    Custom keySeed string must end with with key nonce: ${nonce} Example:

Sign this message to access ${customString} with key nonce: %d

You can define the customString yourself, %d is the nonce received in the account information from .

// CUSTOMER_KEY_SEED = "XXXXXX" + " with key nonce: " + "${nonce}";
const keySeed = CUSTOMER_KEY_SEED.replace(
  "${nonce}",
  accInfo.nonce.toString()
const eddsaKey = await sdk.generateKeyPair({
  web3,
  address: accInfo.owner,
  keySeed,
  walletType: sdk.ConnectorNames.MetaMask,
  chainId: sdk.ChainId.GOERLI,
});
console.log("eddsakey:", eddsaKey.sk);
Step 4: Retrieve fees from the exchange

In order to update your account, you'll need to retrieve the list of available fees from the exchange.

Get updateAccount fee

const fee = await LoopringAPI.globalAPI.getActiveFeeInfo({
  accountId: accInfo.accountId,
});
console.log("fee:", fee);
Step 5: (activate or reset)
 const result = await LoopringAPI.userAPI.updateAccount({
  request: {
    exchange: LOOPRING_EXPORTED_ACCOUNT.exchangeAddress,
    owner: accInfo.owner,
    accountId: accInfo.accountId,
    publicKey: {x: eddsaKey.formatedPx, y: eddsaKey.formatedPy},
    maxFee: {
      tokenId: TOKEN_INFO.tokenMap["LRC"].tokenId,
      volume: fee.fees["LRC"].fee ?? "9400000000000000000",
    },
    keySeed,
    validUntil: LOOPRING_EXPORTED_ACCOUNT.validUntil,
    nonce: accInfo.nonce as number,
  },
  web3,
  chainId: sdk.ChainId.GOERLI,
  walletType: sdk.ConnectorNames.Unknown,
  isHWAddr: false,
});

const {accInfo: updateAccountInfo} =
  await LoopringAPI.exchangeAPI.getAccount({
    owner: LOOPRING_EXPORTED_ACCOUNT.address,
  });
console.log(
  "updateAccount Result: ",
  result,
  "updateAccountInfo:",
  updateAccountInfo
);
Step 6: to check update complete

Check that the publicKey is the same as the value set in the previous step and frozen is false.

'frozen' will be true until updateAccount completes and then it will be set to false.

You can call this API every 10s until updateAccount is complete.

const {accInfo} = await LoopringAPI.exchangeAPI.getAccount({
  owner: LOOPRING_EXPORTED_ACCOUNT.address,
});
Step 7: Retrieve account API key

Get the apiKey by eddsa signature and then the apiKey can be used to get user assets or to call other APIs

const apiKey = (
      await LoopringAPI.userAPI.getUserApiKey(
        {
          accountId: accInfo.accountId,
        },
        eddsaKey.sk
      )
    ).apiKey;
🗳️
Get account
Get apiKey
Loopring exchange address
Website App
GET Account info
Loopring exchange address
get fee
updateAccount
step 2
step 2