web3

Repeating transactions hangs - web3js, local geth

旧巷老猫 提交于 2019-12-05 17:34:32
I have an issue with transactions on my local ethereum network - at some point, transaction hangs & spends a lot of ETH from my account. Here's a sample code: async function send(toAccount, weiVal) { let account = await w3.getDefAccount(); for (let i = 0; i < 100; i++) { let res = await web3.eth.sendTransaction({ from: account, to: toAccount, value: weiVal }); await helper.timeout(2000); } } send('0x5648...', 100000000000000); It hangs at sendTransaction call (promise is never resolved) on some random iteration. The situation remains the same after script restart - transaction passes a few

How to get a value from a “Promise” object

女生的网名这么多〃 提交于 2019-12-02 10:46:57
I started learning ethereum and web3js and noticed some functions on Web3js are asynchronous. What i want to achieve is get the account balance of a wallet and use the data for something else. My code below function getAccountBalance2(address){ var wei, balance //address = document.getElementById("addy").value return new Promise(function(resolve, reject){ web3.eth.getBalance(address, function(error, wei){ if(error){ console.log("Error with address"); }else{ var balance = web3.fromWei(wei, "ether"); var bal = resolve(balance); //console.log(bal); console.log(balance.toNumber()); return balance

How to authenticate and send contract method using web3.js 1.0

馋奶兔 提交于 2019-11-30 05:26:27
I am confused about how I should be executing a contract's method using the web3 1.0 library. This code works (so long as I manually unlock the account first): var contract = new web3.eth.Contract(contractJson, contractAddress); contract.methods .transfer("0x0e0479bC23a96F6d701D003c5F004Bb0f28e773C", 1000) .send({ from: "0x2EBd0A4729129b45b23aAd4656b98026cf67650A" }) .on('confirmation', (confirmationNumber, receipt) => { io.emit('confirmation', confirmationNumber); }); I get this error (if I don't unlock manually first): Returned error: authentication needed: password or unlock The above code

How to authenticate and send contract method using web3.js 1.0

白昼怎懂夜的黑 提交于 2019-11-29 03:56:24
问题 I am confused about how I should be executing a contract's method using the web3 1.0 library. This code works (so long as I manually unlock the account first): var contract = new web3.eth.Contract(contractJson, contractAddress); contract.methods .transfer("0x0e0479bC23a96F6d701D003c5F004Bb0f28e773C", 1000) .send({ from: "0x2EBd0A4729129b45b23aAd4656b98026cf67650A" }) .on('confirmation', (confirmationNumber, receipt) => { io.emit('confirmation', confirmationNumber); }); I get this error (if I

How to return json data to a react state?

↘锁芯ラ 提交于 2019-11-28 14:42:51
I have a react component that makes a .post to an express server (my own server). The server uses web3 to sign a transaction on Ethereum . Once the transaction is included in a block, a json object is returned to the server. It looks like this: { blockHash: '0xcd08039bac40e2865886e8f707ce9b901978c339d3abb81516787b0357f53fbd', blockNumber: 4611028, ...other data... transactionHash: '0x12c65523743ed169c764553ed2e0fb2af1710bb20a41b390276ffc2d5923c6a9', transactionIndex: 1 } I need to store the transactionHash into the state of the above component. I have been searching for 2 days and am probably

Send ERC20 token with web3

喜欢而已 提交于 2019-11-26 20:50:28
I'm currently using 0.2x.x version of Web3 Javascript API. I deployed my custom ERC20 token by creating smart contract in solidity (on REMIX IDE). I installed the MetaMask and had a test on https://wallet.ethereum.org/ to send some custom ERC token to another my account. It worked well. I want to add the 'send custom ERC20 Token' function in my javascript code using Web3. Here is my code below. var http = require('http'); var Web3 = require('web3'); var Tx = require('ethereumjs-tx'); var abi = [{"...."}]; var data = '0x00..'; var contract_addr = '0x00..'; var owner = '0x00..'; var web3 = new