Transaction
π Transaction Module
The transaction module in the ono-web package provides utilities to create, sign, calculate fees, and send transactions on the ONO blockchain network.
π¦ Importing
To use the transaction module, import it as follows:
const { transaction } = require('ono-web');π Functions
1. transaction.setCoreHost(url)
transaction.setCoreHost(url)Sets a custom ONO core node host URL for sending transactions. By default, the host is http://core.ono.gg.
π₯ Parameters
url
URL
URL object of the core host
π Example
transaction.setCoreHost(new URL('http://my-custom-node.com'));2. transaction.calculateFee(amount)
transaction.calculateFee(amount)Calculates the transaction fee based on a percentage of the transaction amount.
Fee formula:
0.0001%of the transaction amount, but never more than 0.01 ONO.
π₯ Parameters
amount
number
Amount to be sent in the transaction
β Returns
numberβ Calculated transaction fee (ONO).
π Example
3. transaction.generateTransaction(to, amount, keyPair)
transaction.generateTransaction(to, amount, keyPair)Generates and signs a new transaction object.
π₯ Parameters
to
string
Recipient's public key (address)
amount
number
Amount of ONO coins to send
keyPair
object
Object with publicKey and privateKey of the sender
β Returns
Transactionβ A signed transaction object ready to send.
π Transaction Object Fields
hash
string
Hash of the transaction
from
string
Sender's public key
to
string
Recipient's public key
amount
number
Amount of ONO coins being sent
fee
number
Transaction fee
timestamp
number
Unix timestamp of transaction creation
signature
string
Cryptographic signature of the hash
π Example
4. transaction.sendTransaction(transactionData)
transaction.sendTransaction(transactionData)Sends a signed transaction to the ONO core network for processing.
π₯ Parameters
transactionData
Transaction
A signed transaction object
β Returns
Promise<Object>β Response from the core server, typically includes success status or error.
π Example
βοΈ Constants
Transaction Fee Percent
0.0001% of transaction amount
Maximum fee cap: 0.01 ONO
π Types
Transaction
Transactionπ‘ Usage Example (Full Flow)
π¨ Notes
Ensure the sender's address has enough ONO balance to cover both the amount and fee.
Transactions are signed locally, ensuring security of private keys.
You can change the ONO core node address via
setCoreHost()if you want to use your own node.
Last updated