Sending MobileCoin

The last step in developing your Wallet Interface is to connect to the build and submit transaction endpoint. Sending transactions enables the Exchange to send MOB to customers, as well as to transfer MOB between accounts that the Exchange controls.

For all transactions, the input txos will be selected automatically unless the input txos are specified during the transaction build step. This is generally not recommended and users should let input txos be automatically selected.

Review the initial balance of your account by calling get_account_status with your account_id generated from the Create an Account section.

Since you are running a test that doesn't require you to review the transaction proposal before submitting it to the ledger, call the convenience method build_and_submit_transaction to send MOB to a public address. Keep note of the transaction_log_id from the response, as we will need for the next step.

async function buildAndSubmitTransaction() {
 const response = await fetch('http://127.0.0.1:9090/wallet/v2', {
   method: 'POST',
   body: `{
     "method": "build_and_submit_transaction",
     "params": {
         "account_id": "1f32a...",
         "recipient_public_address": "3yNzpvKEpis...",
         "amount": {"value": "1000000000", "token_id": "0"}
     },
     "id": 1,
     "jsonrpc": "2.0"
   }`,
   headers: {
     'Content-Type': 'application/json'
   }
 });
 return await response.json();
}

buildAndSubmitTransaction().then((response) => {
 console.log(response);
});

To verify whether the transaction was successful, call get_transaction_log with the transaction_log_id from the previous step. The response will have a field called status which should say succeeded once the transaction clears on the blockchain.

async function getTransactionLog() {
 const response = await fetch('http://127.0.0.1:9090/wallet/v2', {
   method: 'POST',
   body: `{
     "method": "get_transaction_log",
     "params": {
         "transaction_log_id": "ewvvf4...1f32a"
     },
     "id": 1,
     "jsonrpc": "2.0"
   }`,
   headers: {
     'Content-Type': 'application/json'
   }
 });
 return await response.json();
}

getTransactionLog().then((response) => {
 console.log(response);
});

Transactions typically get processed by consensus and are added to the blockchain in a few seconds. Once a block has appeared on the blockchain, it is finalized and does not require waiting for a certain number of blocks to pass (unlike many other cryptocurrencies).

Congratulations, you just sent your first transaction!

Last updated