Payments and transactions
One of the core features that almost every existing Obyte chatbot has is sending and receiving payments. This enables bot developers immediately add payment to the service they could be providing with
Last updated
One of the core features that almost every existing Obyte chatbot has is sending and receiving payments. This enables bot developers immediately add payment to the service they could be providing with
Last updated
When you include a valid Obyte address anywhere in the text of your response to the user, the address will be automatically highlighted in the user's chat window, and after clicking it the user will be able to pay arbitrary amount of arbitrary asset to this address.
When you want to request a specific amount of a specific asset, format your payment request this way:
Example:
Amount is in the smallest units, such as bytes. If you omit &asset=...
part, base asset (bytes) is assumed. If you want to request payment in another asset, indicate its identifier such as oj8yEksX9Ubq7lLc+p6F2uyHUuynugeVq4+ikT67X6E=
for blackbytes (don't forget to url-encode it).
You will likely want to generate a unique payment address per user, per transaction. This code sample might help:
It is possible to request that the payment would be done from any single address wallet or specific single address wallet. This works only in chat messages.
To request the user to pay multiple payments at once, create the below Javascript object objPaymentRequest
which can contain multiple addresses and multiple assets, encode the object in base64, and send it over to the user:
The user's wallet will parse this message, display the multiple payments in a user-readable form, and offer the user to pay the requested amounts. Your payment-waiting code will be called when the payment is seen on the DAG.
If you include a headless wallet
you can get notified when any of your addresses receives a payment
arrUnits
is an array of units (more accurately, unit hashes) that contained any transaction involving your addresses. The event new_my_transactions
is triggered for outgoing transactions too, you should check if the new transaction credits one of the addresses you are expecting payments to.
To get notified when any of your transactions become stable (confirmed), subscribe to my_transactions_became_stable
event:
arrUnits
is again the array of units that just became stable and they contained at least one transaction involving your addresses.
The above events work in both full and light nodes. If your node is full, you can alternatively subscribe to event mci_became_stable
which is emitted each time a new main chain index (MCI) becomes stable:
To send payments, you need to include a headless wallet
and use this function after the headless wallet becomes ready:
asset
is the asset you are paying in (null
for bytes), amount
is payment amount in the smallest units. If the payment was successful, you get its unit
in the callback and can save it or watch further events on this unit.
There are many other functions for sending payments, for example sending multiple payments in multiple assets at the same time, see exports
of https://github.com/byteball/headless-obyte/blob/master/start.js.