Receiving MobileCoin

To receive MOB, you must provide the sender with an account address.

When you created your account in the previous section, the API response included a main_address that you can share to receive funds by default. The main_address is the subaddress for the account at index 0.

Using the main_address generated in the previous section, send a transaction from an account that already has some MOB.

After it has been sent, call get_account_status, which should return with a balance of unspent MOB of the amount that was sent by the sender.

Congratulations, you just received your first transaction!

Generating a Unique Subaddress

If an Exchange wants to have multiple people paying them, the Exchange will not be able to tell which customers have paid because MobileCoin is private, unlike some other cryptocurrencies. MobileCoin has provided public addresses for subaddresses in order to provide a unique public address for each transaction with a customer.

All subaddresses up to unsigned int max (18_446_744_073_709_551_615) are automatically associated with an account; however, the Exchange will need to assign a range of subaddresses during or after account creation in order to get the public address for that subaddress or to check the balance to see if the customer has deposited funds at that subaddress.

To generate a new unique subaddress, you can call the Assign Address For Account endpoint.

async function assignAddressForAccount() {
  const response = await fetch('http://localhost:9090/wallet/v2', {
    method: 'POST',
    body: `{
      "method": "assign_address_for_account",
      "params": {
          "account_id": "1f32a...",
      },
      "jsonrpc": "2.0",
      "id": 1
    }`,
    headers: {
      'Content-Type': 'application/json'
    }
  });
  const json = await response.json();
  return json.result.address;
}

assignAddressForAccount().then((address) => {
  console.log(address.public_address_b58);
});

\

It is important that you keep track of which subaddress is for which customer depositing to your account

Using the public address that we just created, send some MOB to it.

To check the balance of this specific subaddress, you can call the Get Address Status endpoint.

async function getAddressStatus() {
  const response = await fetch('http://localhost:9090/wallet/v2', {
    method: 'POST',
    body: `{
      "method": "get_address_status",
      "params": {
          "address": "1f32a...",
      },
      "jsonrpc": "2.0",
      "id": 1
    }`,
    headers: {
      'Content-Type': 'application/json'
    }
  });
  const json = await response.json();
  return json.result;
}

getAccountStatus().then((accountStatus) => {
  // Show unspent balance for MOB, which is token_id 0.
  // The balance is in pico-MOB, so divide by 1e12 to get whole MOB.
  console.log(`${addressStatus.balance_per_token[0].unspent / 1e12} MOB`);
});

Last updated