Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
typ/web3.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
21 lines (16 sloc)
685 Bytes
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
const Web3 = require("web3"); | |
let web3; | |
const apiLink = "https://rinkeby.infura.io/v3/4b6cf47f5f6e4aca850c45c04a58cf0d"; | |
if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') { | |
// we are in the browser and metamask is running | |
web3 = new Web3(window.web3.currentProvider); | |
} else { | |
// we are on the server or user is not running metamask | |
// set up our own provider that works through infura | |
const provider = new Web3.providers.HttpProvider(apiLink | |
// pass url of remote node | |
// 'https://mainnet.infura.io/v3/4b6cf47f5f6e4aca850c45c04a58cf0d' | |
); | |
web3 = new Web3(provider); | |
} | |
module.exports = web3; |