Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
2,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Web3 = require('web3')
  2. const BigNumber = require('bignumber.js')
  3. const { NOCUSTManager } = require('nocust-client')
  4.  
  5. const web3 = new Web3(new Web3.providers.HttpProvider('https://limbo.liquidity.network/ethrpc'));
  6.  
  7. // const wallets = web3.eth.accounts.wallet.create(1);
  8. // const BOB_PUB = wallets[0].address
  9. // const BOB_PRIV = wallets[0].privateKey
  10. // const ALICE_PUB = wallets[1].address
  11. // const ALICE_PRIV = wallets[1].privateKey
  12. // const EVE_PUB = wallets[2].address
  13. // const EVE_PRIV = wallets[2].privateKey
  14. // console.log(BOB_PUB)
  15. // console.log(BOB_PRIV)
  16. // console.log(ALICE_PUB)
  17. // console.log(ALICE_PRIV)
  18. // console.log(EVE_PUB)
  19. // console.log(EVE_PRIV)
  20. // console.log("Bob PUB ", BOB_PUB);
  21. // console.log("typeof(BOB_PUB) ", typeof(BOB_PUB));
  22. // console.log(wallets)
  23.  
  24. const privateKeys = [
  25.   '0x183fa105ef422892e3332f1f7c34d3edfcfdc6474a3090758fdc494fc5dba6ae',
  26.   '0x6eadfd5d07bde15e4ec55bce76c846584889e9853219866f0e8d9b21230874cf',
  27.   '0xc4aa232a4aeb207d015d7f8d9bba1d88dca301e070249e3110bb2fa394b36eed',
  28.   '0x6cbed15c793ce57650b9877cf6fa156fbef513c4e6134f022a85b1ffdd59b2a1'
  29. ]
  30. var accounts = []
  31.  
  32. privateKeys.forEach(function(key) {
  33.   var account = web3.eth.accounts.privateKeyToAccount(key);
  34.   web3.eth.accounts.wallet.add(account);
  35.   accounts.push(account);
  36. });
  37. const donor = accounts[accounts.length - 1];
  38. const alice = accounts[0];
  39. const bob = accounts[1];
  40.  
  41.  
  42. // Specify to which commit-chain we want to connect
  43. const nocustManager = new NOCUSTManager({
  44.   rpcApi: web3,
  45.   operatorApiUrl: 'https://limbo.liquidity.network/',
  46.   contractAddress: '0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7',
  47.   });
  48.  
  49.  
  50. const refillAlice = async () => {
  51.   console.log("Refill Alice wallet by 1 ether | Prev balance:", await readBalances());
  52.   web3.eth.sendTransaction({
  53.     from: donor.address,
  54.     to: alice.address,
  55.     value: (new BigNumber(1.00)).shiftedBy(18),
  56.     gas: 2100000,
  57.   });
  58.   console.log("After balance:", await readBalances());
  59. }
  60.  
  61. const readOnChainBalances = async () => {
  62.   var balance = await nocustManager.getOnChainBalance(alice.address);
  63.   return web3.utils.fromWei(balance.toString(), 'ether');
  64. }
  65.  
  66.  
  67. const readNOCUSTBalances = async() => {
  68.   var balance = await nocustManager.getNOCUSTBalance(alice.address);
  69.   return web3.utils.fromWei(balance.toString(), 'ether');
  70. }
  71.  
  72. const readBalances = async() => {
  73.   return "(onchain=" + await readOnChainBalances() + " offchain=" + await readNOCUSTBalances() + ")";
  74. }
  75.  
  76. const printBalances = async() => {
  77.   console.log(await readBalances());
  78. }
  79.  
  80. const depositToFETH = async () => {
  81.   console.log('deposit 0.5 Eth -> fEth');
  82.   const transactionHash = await nocustManager.deposit(
  83.     alice.address,                       // Account from which to make a deposit (its private key needs to be in the Web3 instance)
  84.     web3.utils.toWei('0.5','ether'), // Amount to deposit
  85.     web3.utils.toWei('10','gwei'),   // Gas price, 10 Gwei
  86.     500000                         // Gas Limit
  87.   );
  88. }
  89.  
  90. const getTransactions = async() => {
  91.   console.log(await nocustManager.getTransactionsForAddress(
  92.     alice.address
  93.   ))
  94. }
  95.  
  96. const sendToBob = async () => {
  97.  
  98.   // 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.
  99.   // Note that the registration is done implicitly when sending your first transfer.
  100.   console.log("Send to Bob 0.1 fEth");
  101.   accounts.forEach(function(account) {
  102.     nocustManager.registerAddress(account.address)
  103.   })
  104.  
  105.  
  106.   // await nocustManager.registerAddress(ALICE_PUB)
  107.  
  108.   // Send 0.00 fETH on the commit-chain to Alice  
  109.   // 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
  110.   const txId = await nocustManager.sendTransaction({
  111.       to: bob.address,
  112.       // 0.00 fEther in Wei as BigNumber.
  113.       amount: (new BigNumber(0.1)).shiftedBy(18),
  114.       from: alice.address,
  115.    });
  116. }
  117.  
  118. // sendToALice()
  119. // depositToFETH();
  120. printBalances();
  121. // sendToBob();
  122. getTransactions();
  123. // printBalances();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement