This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // web3 has to be injected/present | |
| if (web3js) { | |
| if (web3js.eth.accounts.length) { | |
| // if not locked, get account | |
| const account = web3js.eth.accounts[0]; | |
| // updates UI, state, pull data | |
| } else { | |
| // locked. update UI. Ask user to unlock. | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (web3js) { | |
| switch (web3js.version.network) { | |
| case '1': | |
| console.log('This is mainnet'); | |
| break; | |
| case '2': | |
| console.log('This is the deprecated Morden test network.'); | |
| break; | |
| case '3': | |
| console.log('This is the ropsten test network.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getAccount = () => { | |
| // check if web3 present | |
| if (web3js) { | |
| // return default account | |
| return web3js.eth.accounts[0]; | |
| } | |
| return undefined; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| web3js.eth.getBalance(getAccount(), (err, balance) => { | |
| const balanceInEth = web3js.fromWei(balance, 'ether'); | |
| console.log(`balance ${balanceInEth} ether`); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let account = getAccount(); | |
| let accountInterval = setInterval(() => { | |
| if (getAccount() !== account) { | |
| account = getAccount(); | |
| // update UI, state, pull data | |
| updateEverything(); | |
| } | |
| }, 1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let account = getAccount(); | |
| let accountInterval = setInterval(() => { | |
| if (getAccount() !== account) { | |
| account = getAccount(); | |
| if (account === undefined) { | |
| // if account changed to undefined, that means metamask is now locked | |
| updateEverything(); | |
| } else { | |
| // if account is not undefined, that means metamask is now unlocked | |
| updateEverything(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try { | |
| const account = getAccount(); | |
| const hash = await yourContractInstance.yourMethod.sendTransaction(arg1, arg2, { | |
| from: account, | |
| // if payable, specify value | |
| // value: web3js.toWei(value, 'ether') | |
| }); | |
| // update progress UI | |
| setSubmitting(false); | |
| // reset transaction related form, if any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getTransactionReceipt = async (hash) => { | |
| let receipt = null; | |
| while (receipt === null) { | |
| // we are going to check every second if transation is mined or not, once it is mined we'll leave the loop | |
| receipt = await getTransactionReceiptPromise(hash); | |
| await wait(1000); | |
| } | |
| return receipt; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // both web3 and your contract have be defined | |
| if(web3js && contract) | |
| { | |
| const yourEvent = contract.YourEventName(); | |
| yourEvent.watch(function(error, result) { | |
| if (!error) { | |
| // Callback return | |
| // Object - An event object as follows: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.24; | |
| /** | |
| * @title FiatTokenProxy | |
| * @dev This contract proxies FiatToken calls and enables FiatToken upgrades | |
| */ | |
| contract FiatTokenProxy is AdminUpgradeabilityProxy { | |
| constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) { | |
| } |