iota-payment

0.0.67 • Public • Published

iota payment module

License: MIT node Dependency Status Join Discord Follow on Twitter

How to Use

Still in development and testing. Unexpected errors and loss of funds may occur. Feedback is welcome!

This module can easily extend your nodejs or express app.

Install

npm i iota-payment

Usage

Create a .env file with your settings

Always start with a new unused seed!

Minimum requirement to use it in the comnet:

seed=REPLACEWITHEIGHTYONETRYTESEED

If you want to send payouts, without receiving IOTA tokens via payments first, send the tokens to the first address of the seed (index 0) (is displayed on first start)

You can get test tokens from https://faucet.comnet.einfachiota.de

Example

const { createPaymentRequest, onEvent, sendPayout, getBalance } = require('iota-payment')
 
async function main() {
  try {
    //create a payment (receiving address), data is optional and is only stored locally
    let payment = await createPaymentRequest({ value: 1, data: { number: 1 } })
    //send a payout with zero value
    let payout = await sendPayout({ address: 'VO9H9GFNRTOLPUHM9MACFWSUFLNLDYCTKIPXCYLTNNNDMURPUIXNVBYQMRKOJDEYM9UDESGXBIWASIDRBFOBHCJGZD', value: 0 })
    //get account balance
    let balance = await getBalance()
    console.log("Balance:", balance)
  } catch (err) {
    console.error(err);
  }
}
 
//run
main()
 
//Create an event handler which is called, when a payment was successfull
let onPaymentSuccess = (payment) => {
  //your code
  console.log(`Payment number ${payment.data.number} was paid:`, payment);
}
onEvent('paymentSuccess', onPaymentSuccess);

More examples

Documentation

Additional settings you can add to the .env to override the defaults:

#time after which payments aren't checked anymore in minutes (4320 = 3 days to pay, transactions after that are ignored) 
maxPaymentTime=4320
#set custom IOTA nodes 
iotaNodes=["https://nodes.comnet.thetangle.org:443"]
#get basic logs 
debug=basic
#get all logs 
debug=full
#use the mainnet defaults (mainnet nodes, explorer link, mwm) 
network=mainnet
#override mwm 
mwm=14
#override explorer tx link 
explorerTxLink=https://comnet.thetangle.org/transaction/
#don't check if addresses were spent from 
wereAddressSpentCheck=false
#custom limit for how many txs a bundle can have, minimum is 4 
maxBundleSize=7
#value for payments with the API 
value=1
#set origings for websocket connection 
socketOrigins=['http://localhost:*''http://127.0.0.1:*']
#limit the payment (address) generation over the API in seconds; to allow only 1 every 10 seconds: 
minPaymentInterval=10
#use mongodb 
db=mongodb
#custom mongodb url 
mongodbUrl=mongodb://127.0.0.1:27017/
#enable zmq to detect incoming transactions faster 
zmq=true
zmqNode=tcp://tanglebeat.com:5556
#payment success in seconds if a valid transaction was sent (not confirmed), funds may never arrive 
fastButRisky=true
#delete payments and payouts at the moment they get confirmed 
deletePaidEntries=true
 
 
# --------- 
# Dashboard 
# --------- 
## username for login - default: admin 
username=your_user_name
## password for login - default: password 
password=password
## jwt_token - default: ipm_ipm_ipm 
jwt_token=your_jwt_token

Contribute

Have a look at CONTRIBUTING.md.

License

The MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i iota-payment

Weekly Downloads

0

Version

0.0.67

License

MIT

Unpacked Size

2.98 MB

Total Files

180

Last publish

Collaborators

  • huhn