Skip to content
This repository has been archived by the owner. It is now read-only.
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
import * as path from 'path'
import * as fs from 'fs-extra'
import BigNumber from 'bignumber.js'
import * as Web3 from 'web3'
import Machinomy from 'machinomy'
import HDWalletProvider from '@machinomy/hdwallet-provider'
import Logger from '@machinomy/logger'
const PROVIDER = process.env.PROVIDER || ''
const MNEMONIC = process.env.MNEMONIC || 'peanut giggle name tree canoe tube render ketchup survey segment army will'
const LOG = new Logger('machinomy-sender')
async function run () {
const provider = HDWalletProvider.http(MNEMONIC, PROVIDER, 2)
const senderAccount = await provider.getAddress(0)
const receiverAccount = await provider.getAddress(1)
const web3 = new Web3(provider)
const minimumChannelAmount = new BigNumber(1).shift(4)
const channelValue = new BigNumber(1).shift(6)
const paymentPrice = new BigNumber(200000)`PROVIDER = ${PROVIDER}`)`MNEMONIC = ${MNEMONIC}`)
const machinomy = new Machinomy(
web3, {
databaseUrl: 'nedb://sender-receiver/database.nedb',
minimumChannelAmount: minimumChannelAmount
)`Start opening Machinomy channel between sender ${senderAccount} and receiver ${receiverAccount} with value ${channelValue} Wei`)`For remote Ethereum nodes (e.g. Rinkeby or Ropsten) it can taking a 30-60 seconds.`)
await, channelValue)`Channel was opened.`)`Trace the last transaction via${senderAccount}`)
const payment = await machinomy.payment({
receiver: receiverAccount,
price: paymentPrice
})'Payment: ')
fs.writeFileSync('payment.json', JSON.stringify(payment.payment))'Sender done.')
run().catch(err => {