How to use the web3.givenProvider function in web3

To help you get started, we’ve selected a few web3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0mkara / etheratom / lib / web3 / web3.js View on Github external
subscribeToWeb3Events() {
		if(!this.web3Subscriptions) {
			return
		}
		const rpcAddress = atom.config.get('etheratom.rpcAddress');
		const websocketAddress = atom.config.get('etheratom.websocketAddress')
		if(typeof this.web3 !== 'undefined') {
			this.web3 = new Web3(this.web3.currentProvider);
		} else {
			this.web3 = new Web3(Web3.givenProvider || new Web3.providers.HttpProvider(rpcAddress));
			if(websocketAddress) {
				this.web3.setProvider(new Web3.providers.WebsocketProvider(websocketAddress));
			}
			this.helpers = new Web3Helpers(this.web3);
		}
		this.view = new View(this.store, this.web3);
		if(Object.is(this.web3.currentProvider.constructor, Web3.providers.WebsocketProvider)) {
			console.log("%c Provider is websocket. Creating subscriptions... ", 'background: rgba(36, 194, 203, 0.3); color: #EF525B');
			// newBlockHeaders subscriber
			this.web3.eth.subscribe('newBlockHeaders')
				.on("data", (blocks) => {
					//console.log("%c newBlockHeaders:data ", 'background: rgba(36, 194, 203, 0.3); color: #EF525B');
					//console.log(blocks);
				})
				.on('error', (e) => {
					console.log("%c newBlockHeaders:error ", 'background: rgba(36, 194, 203, 0.3); color: #EF525B');
github tyleryasaka / identity-proposals / test / identity.js View on Github external
var Identity = artifacts.require('Identity')
var Counter = artifacts.require('Counter')
var KeyManager = artifacts.require('KeyManager')
var IdentityRegistry = artifacts.require('IdentityRegistry')
var ClaimRegistry780 = artifacts.require('ClaimRegistry780')
var IdentityFactory = artifacts.require('IdentityFactory')
var MetaWallet = artifacts.require('MetaWallet')
var SimpleToken = artifacts.require('SimpleToken')
var Web3 = require('web3')

const claimKey = '0x0000000000000000000000000000000000000000000000000000000000000000'
const claimValue = '0x0000000000000000000000000000000000000000000000000000000000000123'
const OWNER_KEY = '0x0000000000000000000000000000000000000000000000000000000000000000'
const operationCall = 0
const web3 = new Web3(Web3.givenProvider)

const getEncodedCall = (web3, instance, method, params = []) => {
  const contract = new web3.eth.Contract(instance.abi)
  return contract.methods[method](...params).encodeABI()
}

const sign = async (params, account) => {
  const signatureData = web3.utils.soliditySha3(...params)
  return await web3.eth.sign(signatureData, account)
}

const assertVMExecption = async (fn) => {
  try {
    await fn()
    throw null;
  } catch (error) {
github mosaicdao / mosaic-contracts / test / test_lib / web3.js View on Github external
const Web3 = require('web3');

const web3 = new Web3(Web3.givenProvider || 'http://localhost:8545');

module.exports = web3;
github ProofSuite / proof-cryptodollar / src / helpers / providers.js View on Github external
export const getInjectedProvider = () => {
  const provider = Web3.givenProvider
  if (!provider) console.log('no given provider found')

  return provider
}
github gnosis / conditional-markets-interface / app / src / Modals / Connect.js View on Github external
const troubleshootMetamask = useCallback(async () => {
    const config = await import(`../conf`);

    let account;
    try {
      const web3Data = await tryProvider(Web3.givenProvider, config.networkId);
      account = web3Data.account;
    } catch (err) {
      if (err.message === "provider not available") {
        setErrorMessages({
          METAMASK: {
            message: (
              <>
                <a rel="noopener noreferrer" href="https://metamask.io">
                  Please install Metamask
                </a>
              
            )
github zxl9171 / eth-notebook / src / components / MarkdownEditor.react.js View on Github external
\`\`\`
def helloWorld():
  print("Hello World!")
\`\`\`

## Tables?

| Feature | Support |
| ------ | ----------- |
| tables | ✔ |
| alignment | ✔ |
| wewt | ✔ |

`

const web3 = new Web3(Web3.givenProvider);

var hexEncode = function(text){
  text = unescape(encodeURIComponent(text))
  var digits = "0123456789ABCDEF"
  var hex = ""
  let i,hc,lc;
  for (i = 0; i &lt; text.length; i++) {
      hc = (text.charCodeAt(i) &gt;&gt;&gt; 4) &amp; 0x0F
      lc = text.charCodeAt(i) &amp; 0x0F
      hex += digits[hc]
      hex += digits[lc]
  }
  return hex
}

class MarkdownEditor extends React.Component {
github dappuniversity / eth-todo-list-react / src / App.js View on Github external
async loadBlockchainData() {
    const web3 = new Web3(Web3.givenProvider || "http://localhost:8545")
    const accounts = await web3.eth.getAccounts()
    this.setState({ account: accounts[0] })
    const todoList = new web3.eth.Contract(TODO_LIST_ABI, TODO_LIST_ADDRESS)
    this.setState({ todoList })
    const taskCount = await todoList.methods.taskCount().call()
    this.setState({ taskCount })
    for (var i = 1; i &lt;= taskCount; i++) {
      const task = await todoList.methods.tasks(i).call()
      this.setState({
        tasks: [...this.state.tasks, task]
      })
    }
    this.setState({ loading: false })
  }