Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Web3 = require('web3')
- const BigNumber = require('bignumber.js')
- const { NOCUSTManager } = require('nocust-client')
- const web3 = new Web3(new Web3.providers.HttpProvider('https://limbo.liquidity.network/ethrpc'));
- // const wallets = web3.eth.accounts.wallet.create(1);
- // const BOB_PUB = wallets[0].address
- // const BOB_PRIV = wallets[0].privateKey
- // const ALICE_PUB = wallets[1].address
- // const ALICE_PRIV = wallets[1].privateKey
- // const EVE_PUB = wallets[2].address
- // const EVE_PRIV = wallets[2].privateKey
- // console.log(BOB_PUB)
- // console.log(BOB_PRIV)
- // console.log(ALICE_PUB)
- // console.log(ALICE_PRIV)
- // console.log(EVE_PUB)
- // console.log(EVE_PRIV)
- // console.log("Bob PUB ", BOB_PUB);
- // console.log("typeof(BOB_PUB) ", typeof(BOB_PUB));
- // console.log(wallets)
- const privateKeys = [
- '0x183fa105ef422892e3332f1f7c34d3edfcfdc6474a3090758fdc494fc5dba6ae',
- '0x6eadfd5d07bde15e4ec55bce76c846584889e9853219866f0e8d9b21230874cf',
- '0xc4aa232a4aeb207d015d7f8d9bba1d88dca301e070249e3110bb2fa394b36eed',
- '0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1'
- ]
- var accounts = []
- privateKeys.forEach(function(key) {
- var account = web3.eth.accounts.privateKeyToAccount(key);
- web3.eth.accounts.wallet.add(account);
- accounts.push(account);
- });
- const donor = accounts[accounts.length - 1];
- const alice = accounts[0];
- const bob = accounts[1];
- // Specify to which commit-chain we want to connect
- const nocustManager = new NOCUSTManager({
- rpcApi: web3,
- operatorApiUrl: 'https://limbo.liquidity.network/',
- contractAddress: '0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7',
- });
- const refillAlice = async () => {
- console.log("Refill Alice wallet by 1 ether | Prev balance:", await readBalances());
- web3.eth.sendTransaction({
- from: donor.address,
- to: alice.address,
- value: (new BigNumber(1.00)).shiftedBy(18),
- gas: 2100000,
- });
- console.log("After balance:", await readBalances());
- }
- const readOnChainBalances = async () => {
- var balance = await nocustManager.getOnChainBalance(alice.address);
- return web3.utils.fromWei(balance.toString(), 'ether');
- }
- const readNOCUSTBalances = async() => {
- var balance = await nocustManager.getNOCUSTBalance(alice.address);
- return web3.utils.fromWei(balance.toString(), 'ether');
- }
- const readBalances = async() => {
- return "(onchain=" + await readOnChainBalances() + " offchain=" + await readNOCUSTBalances() + ")";
- }
- const printBalances = async() => {
- console.log(await readBalances());
- }
- const depositToFETH = async () => {
- console.log('deposit 0.5 Eth -> fEth');
- const transactionHash = await nocustManager.deposit(
- alice.address, // Account from which to make a deposit (its private key needs to be in the Web3 instance)
- web3.utils.toWei('0.5','ether'), // Amount to deposit
- web3.utils.toWei('10','gwei'), // Gas price, 10 Gwei
- 500000 // Gas Limit
- );
- }
- const getTransactions = async() => {
- console.log(await nocustManager.getTransactionsForAddress(
- alice.address
- ))
- }
- const sendToBob = 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.
- console.log("Send to Bob 0.1 fEth");
- accounts.forEach(function(account) {
- nocustManager.registerAddress(account.address)
- })
- // 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({
- to: bob.address,
- // 0.00 fEther in Wei as BigNumber.
- amount: (new BigNumber(0.1)).shiftedBy(18),
- from: alice.address,
- });
- }
- // sendToALice()
- // depositToFETH();
- printBalances();
- // sendToBob();
- getTransactions();
- // printBalances();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement