Last active
March 3, 2019 19:21
-
-
Save mr-fool/8dabe21a0b39ceb883a6ca3afa3dd6ea to your computer and use it in GitHub Desktop.
This file contains 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
import getWeb3 from './web3'; | |
import Web3 from "web3"; | |
const web3 = getWeb3(); | |
const address = '0x8895B2ed3EF4F4f66d048A3F215aC0DeA9Eb6777'; | |
const abi =[ { constant: true, | |
inputs: [], | |
name: 'manager', | |
outputs: [ [Object] ], | |
payable: false, | |
stateMutability: 'view', | |
type: 'function', | |
signature: '0x481c6a75' }, | |
{ constant: false, | |
inputs: [], | |
name: 'pickWinner', | |
outputs: [], | |
payable: false, | |
stateMutability: 'nonpayable', | |
type: 'function', | |
signature: '0x5d495aea' }, | |
{ constant: true, | |
inputs: [], | |
name: 'getPlayers', | |
outputs: [ [Object] ], | |
payable: false, | |
stateMutability: 'view', | |
type: 'function', | |
signature: '0x8b5b9ccc' }, | |
{ constant: false, | |
inputs: [], | |
name: 'enter', | |
outputs: [], | |
payable: true, | |
stateMutability: 'payable', | |
type: 'function', | |
signature: '0xe97dcb62' }, | |
{ constant: true, | |
inputs: [ [Object] ], | |
name: 'players', | |
outputs: [ [Object] ], | |
payable: false, | |
stateMutability: 'view', | |
type: 'function', | |
signature: '0xf71d96cb' }, | |
{ inputs: [], | |
payable: false, | |
stateMutability: 'nonpayable', | |
type: 'constructor', | |
constant: undefined, | |
signature: 'constructor' } ]; | |
export default new web3.eth.Contract(abi,address); |
This file contains 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
import Web3 from "web3"; | |
let getWeb3 = new Promise(async function(resolve, reject) { | |
// Wait for loading completion to avoid race conditions with web3 injection timing. | |
var results; | |
let _web3; | |
try { | |
if (window.ethereum) { | |
_web3 = new Web3(window.ethereum); | |
await window.ethereum.enable(); | |
} | |
// Checking if Web3 has been injected by the browser (Mist/MetaMask) | |
else if (typeof window.web3 !== "undefined") { | |
// Use Mist/MetaMask's provider. | |
_web3 = new Web3(window.web3.currentProvider); | |
console.log("Injected web3 detected."); | |
} else { | |
// Fallback to localhost if no web3 injection. We've configured this to | |
// use the development console's port by default. | |
var provider = new Web3.providers.HttpProvider( | |
"https://rinkeby.infura.io/v3/727c635298344b37961bb1755114f08b" | |
); | |
_web3 = new Web3(provider); | |
console.log("No web3 instance injected, using Infuria web3."); | |
} | |
results = { | |
web3: _web3 | |
}; | |
resolve(results); | |
} catch (e) { | |
throw new Error(e.message || e); | |
} | |
}); | |
export default getWeb3; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment