Hot answers tagged

12

I think you're looking for fromWei. In web3.js 0.2x.x: web3.fromWei(n, 'ether')


9

This line ... nonce: window.web3.utils.toHex(window.web3.eth.getTransactionCount(fromAccount)), ... relies on a reliable transaction count from Infura. The problem is it's not as reliable (or even close) as you need it to be. This method will produce unreliable, inconsistent results as you have observed. Some background will help explain what is going on ...


8

Those two products are completely different. Metamask is a blockchain wallet (account management) that secures a private key and helps you to interact with an Ethereum Blockchain network (like mainnet, testnet, private networks or local). It's a Browser extension (Chrome/Firefox/Brave) that triggers a popup when a user tries to send a transaction to the ...


6

In web3.js 1.0, use this: web3.utils.fromWei(number [, unit]) doc


6

There is so much competition in the JavaScript framework space and they are basically all good if you have good command of it ... I think MeteorJS is popular in this space not because it is better than React but because one important member of the Ethereum Foundation Fabian Vogelsteller (main contributor of the JavaScript library Web3) wrote several books ...


5

You don't need to call the sendTransaction function explicitly, just call the function of your smart-contract like this: contract.buyTicket(3000, { from: '0x5c1a92217e456a7eB4a051B567FC751A534991a3', gas: 1000000, value: web3.toWei(1, 'ether') }); also don't forget to define the gas-limit edit: you don't need to instanciate a ...


4

Change peopleContract to this: var peopleContract = new ETHEREUM_CLIENT.eth.Contract(peopleContractABI, peopleContractAddress); web3 docs on specifying parameters for your contract object: https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#parameters EDIT: above solution applies to web3.js 1.0. .atworks on web3.js 0.x.x


4

In your index.js file you need to pass drizzle instance into the App component as props: ReactDOM.render(<App drizzle={drizzle} />, document.getElementById("root")); You should also declare your consts before ReactDOM.render: ... // let drizzle know what contracts we want const options = { contracts: [MyStringStore] }; // setup the drizzle store ...


4

I think you should use await Contract.methods.getPvoteStruct(0,0).call() Also returning arrays from structs is a pain. See web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12


3

The simplest way is to use react-web3-provider component. Add the Web3Provider to your root React component: import Web3Provider from 'react-web3-provider'; ReactDOM.render( <Web3Provider defaultWeb3Provider={ (cb) => cb(new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/YOUR_API_KEY"))) } loading="Loading..." &...


3

Basic JavaScript works perfectly fine in React. The most popular Ethereum JS library today seems to be the Web3 JavaScript API. Review their API to find your solutions and specifically balance requests. Ethers.js is another fantastic library. Here is a snippet of code from our apps. /* Import the ethers.js library. */ import ethers from 'ethers' /* ...


3

There should be an account address associated to any transaction. While using truffle console, it automatically take the default account but not while using web3. Try to associate an account address to your transaction like below: notaryContract.Register('0xcc82fa55789663402c013a497eac268172af7f9d', this.state.setFirstName, this.state.setLastName, this....


3

I figured it out by doing the following: const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); const abi = [{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"payable":false,"type":"fallback"}]; const address = "0x3E2A850420e024d2f269d45F85a24Dc6F586277D"; ...


3

Check out this guide. To summarize: first check whether web3 already exists. If it does, initialize a Web3 object with web3.currentProvider. Otherwise, use your node's URL


3

As Rob Hitchens explained, Infura is architected via a load balancer with multiple nodes behind it. This means that two of the same requests to Infura can result in different responses because each request could hit a different node. Sometimes you will get responses from stale blocks, nodes with different transactions in their mempools, or nodes that don't ...


3

OK, so I figured it out. I was misled by Redux DevTools that made me think that the action was not dispatched because when I filtered on the action's name, I didn't see anything. But apparently, the action was dispatched, but not picked up by Saga because there was a mistake in my initialization there: export default function* root() { yield all( ...


3

If you are using accounts[0] as your default account, modify this line: await contract.distributePrizes(); to: await contract.distributePrizes({from: accounts[0]}); Or when you are creating your web3 object: let accounts = await web3.eth.getAccounts(); web3.eth.defaultAccount = accounts[0] Another option: if you have geth or truffle installed, open a ...


2

You can use truffle-box It does not come with a reducer for web3, which will be helpful if you are looking to support browser based wallets. Here's a fork with a web3 reducer that let's you pass web3 to components as a prop


2

DevCon2 helped me :) React Boilerplate https://github.com/silentcicero/react-dapp-boilerplate


2

Truffle performs a different role to React. Truffle handles interaction with contracts on a blockchain, whereas React is a user interaction framework. So you can't replace Truffle with React. You may well want to use both Truffle and React in your application. There's no particular problem using Truffle in production. The comment you heard may have referred ...


2

You can pass the gas value in contract method invocation like below: return simpleStorageInstance.submitPass("Intro 2 Truffle", "Alain", "Gold", {from: accounts[0], gas: 200000}) You can check the actual required gas value in testrpc console. convert that from hex to decimal and that will be your required gas value. You can put that gas amount in the ...


2

This strikes me as bad code. When a number is returned from a contract, it's of type BigNumber in JavaScript. It can be converted to a string with .toString(). It can also be converted to a number via .toNumber(), but be careful about loss of precision. The reason BigNumber is used in the first place is because JavaScript can't handle large numbers. It's ...


2

It sounds confusing and basing on the version of web3 you have the syntax is different. According to the error you got at the first place seems like you are using web3 1.0. However the instance code is for the version 0.2.x.x Just to clarify, this is how your code will look like in case you're using web3 1.0 import Web3 from 'web3'; const web3 = new Web3(...


2

It's not ready so that means its asynchronous, so in your componentDidMount() you need something like this: componentDidMount() { const value = await contractName.methods.getValue().call(); } Now, when you use the await syntax that means you do have to mark the componentDidMount() as being async like so: async componentDidMount() { const value = await ...


2

I fixed it with these steps (note step 1 takes some time): Run command prompt as administrator npm install --global--production windows-build-tools npm install --global node-gyp in package.json file put this in devdependecies section: "deepmerge": "^2.1.0", "is-plain-object": "^2.0.4" navigate to directory of drizzle unboxes app and run npm install or ...


2

Are you installing with admin rights in console? I used admin powershell to install everything on windows. You can try rebuilding manually : node-gyp rebuild


2

web3 instance can be accessed via context in components. for more information please check https://github.com/trufflesuite/drizzle-react/issues/22


2

you will need to access the drizzle context object, in the react component. I assume you are working on the 'Home.js' component. For example: this.drizzle = context.drizzle in the constructor of the component and see https://github.com/trufflesuite/drizzle-react/issues/22, Once you have that working then, this.drizzle.contracts.TutorialToken.address or ...


2

I think what you are trying to do here is resolve a bunch of promises, in which case, I would normally create an array of promises, and resolve them all with Promise.all(). Something like this: // This is just an example of a function that returns a promise function delayedNum (num) { return new Promise(resolve => { setTimeout(() => { ...


2

Had the same error. It appears that a dependency is not included in node_modules when using truffle unbox react. Just install the missing dependency and the error will go away: npm install bignumber.js


Only top voted, non community-wiki answers of a minimum length are eligible