Skip to content

Integrate Omni Core to receive payments

dexX7 edited this page Jun 29, 2018 · 8 revisions

When integrating Omni Core to receive payments, the following points may be relevant:

Generate receiving addresses

To generate a new destination to receive payments, the getnewaddress RPC can be used. It is recommended to generate new destinations for every incoming payment.

Check token balances

There are three RPCs to check balances: omni_getbalance, omni_getallbalancesforid and omni_getallbalancesforaddress. Because the global state of the Omni Layer depends on the order of transactions in blocks, relying on unconfirmed balances should never be done.

Get information about incoming transactions

With the omni_gettransaction RPC information about Omni Layer transactions can be retrieved. When a user sends tokens, it is usually done with a Simple Send transaction, which transfers tokens from the sendingaddress to the referenceaddress. An example output is given in the referenced documentation. It is crucial to check, whether the transaction is valid! This is indicated by the valid field.

To list all Omni Layer transactions of a block, the omni_listblocktransactions RPC can be used. To list unconfirmed Omni Layer transactions, the RPC omni_listpendingtransactions is available.

There is a ZMQ interface to receive push notifications about new blocks. The configuration option blocknotify may also be used to indicate, whether a new block was found. To get information about the lenght of the chain, the RPCs getblockcount and getbestblockhash can be used.

Important: validate payments

When checking transactions with omni_gettransaction it is necessary to confirm, whether the transaction is indeed valid, which is indicated by the valid field. It is also highly recommended to confirm the actual balance of an user with the balance related RPCs described above.

Block reorganizations

Omni Layer transactions are depending on the order of transactions in blocks. In case of a block reorganization, the state can change. If this happens, previous information should be discarded and new information should be gathered. It is especially important to verify a user has enough balance, which can be done with the balance related RPCs as described above.

Send or sweep tokens

A specified amount of tokens can be sent with the omni_send RPC. To send a transaction, bitcoins are needed to cover transaction fees. See this post for more details.

It is also possible to sweep all available tokens of a destination with the omni_sendall RPC, which is recommended, because it ensures no tokens are left behind and it saves fees due to it's slightly lower payload.