const Web3 = require('web3') // Web3 1.0.0-beta.37 only for now
const BigNumber = require('bignumber.js')
const { NOCUSTManager } = require('nocust-client')
// Setup web3 with Infura
const web3 = new Web3(new Web3.providers.HttpProvider('https://rinkeby.infura.io/'));
const wallets = web3.eth.accounts.wallet.create(2);
const BOB_PUB = wallets[0].address
const BOB_PRIV = wallets[0].privateKey
const ALICE_PUB = wallets[1].address
const ALICE_PRIV = wallets[1].privateKey
// Specify to which commit-chain we want to connect
const nocustManager = new NOCUSTManager({
operatorApiUrl: 'https://rinkeby.liquidity.network/',
contractAddress: '0x66b26B6CeA8557D6d209B33A30D69C11B0993a3a',
const sendToALice = async () => {
// Register Alice and Bob with the commit-chain. This is required to be done at least once per address in order to receive commit-chain transaction.
// Note that the registration is done implicitly when sending your first transfer.
await nocustManager.registerAddress(BOB_PUB)
await nocustManager.registerAddress(ALICE_PUB)
// Send 0.00 fETH on the commit-chain to Alice
// In this example, we send 0 fETH, because Alice doesn't have any funds yet, and yes, we can send 0-value commit-chain transaction, haha
const txId = await nocustManager.sendTransaction({
// 0.00 fEther in Wei as BigNumber.
amount: (new BigNumber(0.00)).shiftedBy(-18),
console.log("Transfer to Alice sent ! Transaction ID: ", txId)