const getWeb3 = () => { return (web3 = new Web3( new Web3.providers.HttpProvider("http://localhost:8545") // ganache-cli address )); }
async componentDidMount(){ const manager = await lottery.methods.manager().call(); const players = await lottery.methods.getPlayers().call(); const balance = await web3.eth.getBalance(lottery.options.address); this.setState({manager, players, balance}); }
this.web3.eth .getCode(address) .then( code => code === "0x0" || code === "0x" ? resolve(false) : resolve(true) ) .catch(err => reject(err))
this.web3.eth.getAccounts().then(accounts => { console.log(`Updating USER from ${this.currentUser} to ${accounts[0]}`) this.currentUser = accounts[0] return accounts[0] })
const run = async () => { // Get web3 const Web3 = require('web3') const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) // Get address const accounts = await web3.eth.getAccounts() console.dir(accounts) // get balance const balance = await web3.eth.getBalance(accounts[0]) console.log(`balance : ${balance}`) }
async onClick() { try { //Grab all the accounts from metamask const accounts = await web3.eth.getAccounts(); this.setState({ message: "Choosing a winner..." }); //Send transaction to enter method with desired account await lottery.methods.pickWinner().send({ from: accounts[0] }); this.setState({ message: "A winner has been picked!" }); } catch (e) { console.log(e); } }
async handleCalculation() { let sum = await myContractA.methods.sumNumbers().call(); this.setState({calculated: sum}); }
web3.eth.getTransactionReceipt(this.state.transactionHash, (err, txReceipt)=>{ console.log(err,txReceipt); this.setState({txReceipt}); })
web3.eth.sendTransaction(tx).then((receipt)=>{ console.log("receipt",receipt) this.setState({receipt:receipt}) });
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex')).then((receipt)=>{ console.log("receipt",receipt) this.setState({rawReceipt:receipt}) });
async setWeb3() { // set the provider you want from Web3.providers const web3 = new Web3(new Web3.providers.HttpProvider(this.providerUrl)); return web3; }
async componentDidMount(){ const manager = await lottery.methods.manager().call(); const players = await lottery.methods.getPlayers().call(); const balance = await web3.eth.getBalance(lottery.options.address); this.setState ({ manager, players, balance }); }
async componentDidMount() { //Don't have to specify from property with MetaMask inside call const manager = await lottery.methods.manager().call(); const players = await lottery.methods.getPlayers().call(); const balance = await web3.eth.getBalance(lottery.options.address); this.setState({ manager, players, balance }); }
async handleCalculation() { let sum = await myContractA.methods.sumNumbers().call(); this.setState({calculated: sum}); }