Trading Account

To communicate with ZKX, you should have a Starknet Account. The easiest way to create one is using ZKX Web UI.

Starknet account could have up to 255 trading accounts. Every trading account is identified by an index starting with 0. A trading account with an index 0 has a special meaning and is named "Basic". The basic account is for use with OG Basic Trading. Accounts with indexes > 0 are for Pro Trading.

By default, there are no trading accounts active for a Starknet Account. The trading account is activated from the Starknet Account to the trading account on the first deposit. Deposit is done via ZKX Starknet Smart Contract. The easiest way is to use Web UI to send a deposit transaction.

The only supported collateral for now is USDC Starkway, the easiest way to get it is to transfer USDC from Ethereum wallet to the Starknet Account using Starkway Bridge. For the test environment, you could request USDC from our faucet (see 'USDC Faucet Web UI' in Introduction) or using the direct POST request:

POST /faucet
{ "l2Address" : "0x....." }

On the API level, trading accounts are identified by AccountId, which is a hashed form of account address and index. Below here is the snippet showing how to calculate it with js.

  function calculateAccountId(params: {
    index: number; // must be between [0, 255]
    address: string; // must be in hex
  }): string {
    let address = params.address;

    if (!address.includes('0x')) {
      throw new Error('Invalid account address');
    } else {
      address = address.substring(2);
    }

    // ex: "0x1ab" should be "0x01ab"
    if (address.length % 2 !== 0) {
      address = `0${address}`;
    }

    const indexLeBytes = numberToU8a(params.index);
    const addressLeBytes = hexToU8a(address).reverse();

    // just to be sure
    if (addressLeBytes.length > 32) {
      throw new Error('account address should be <= 32 bytes');
    }

    const concatenatedBytes = new Uint8Array(33);

    concatenatedBytes.set(addressLeBytes, 0);
    concatenatedBytes.set(indexLeBytes, 32);

    const hashAsBytes = blake2AsU8a(concatenatedBytes, 256);
    const hashAsString = u8aToHex(hashAsBytes);

    return hashAsString;
  }

Last updated