Skip to content

Instantly share code, notes, and snippets.

View ylv-io's full-sized avatar
🤑
Building Internet Money

Igor Yalovoy ylv-io

🤑
Building Internet Money
View GitHub Profile
// 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.
}
}
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.');
const getAccount = () => {
// check if web3 present
if (web3js) {
// return default account
return web3js.eth.accounts[0];
}
return undefined;
};
web3js.eth.getBalance(getAccount(), (err, balance) => {
const balanceInEth = web3js.fromWei(balance, 'ether');
console.log(`balance ${balanceInEth} ether`);
});
let account = getAccount();
let accountInterval = setInterval(() => {
if (getAccount() !== account) {
account = getAccount();
// update UI, state, pull data
updateEverything();
}
}, 1000);
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();
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
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;
};
// 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:
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) {
}