Setup a Loopring Account
Open an account via the Loopring DEX.
Last updated
Was this helpful?
Open an account via the Loopring DEX.
Last updated
Was this helpful?
Please update SDK after v3.1.5 and use UnlockAccount with `account.publicKey or `generateKeyPair` with `account.publicKey`
There are two ways to register an account on the Loopring DEX to get an account ID:
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.
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.
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,
});
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.
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);
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);
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);
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
);
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,
});