How to use the web3-provider-engine/subproviders/cache.js function in web3-provider-engine

To help you get started, we’ve selected a few web3-provider-engine 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 MetaMask / zero-client / zero-provider.js View on Github external
var engine = new ProviderEngine()

  // static - hardcoded responses
  engine.addProvider(new StaticSubprovider({
    web3_clientVersion: 'MetaMask-ZeroClient/v0.0.0/javascript',
    net_version: '1',
    net_listening: true,
    net_peerCount: '0xc',
    eth_protocolVersion: '63',
    eth_hashrate: '0x0',
    eth_mining: false,
    eth_syncing: true,
  }))

  // cache
  engine.addProvider(new CacheSubprovider())

  // filters - e.g.: eth_newBlockFilter
  engine.addProvider(new FilterSubprovider())

  // vm - e.g.: eth_call
  engine.addProvider(new VmSubprovider())

  // data source - e.g.: eth_getBalance
  engine.addProvider(new RpcSubprovider({
    rpcUrl: opts.rpcUrl || 'https://rpc.metamask.io/',
  }))

  engine.on('block', function(block){
    console.log('================================')
    console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
    console.log('================================')
github brave / ethereum-remote-client / app / scripts / lib / metamask-provider.js View on Github external
function metamaskProvider(opts){

  var engine = new ProviderEngine()

  // nonce tracker
  engine.addProvider(new NonceTrackerSubprovider())

  // cache layer
  engine.addProvider(new CacheSubprovider())

  // static results
  engine.addProvider(new FixtureSubprovider({
    web3_clientVersion: 'MetaMask-ProviderEngine/v0.0.0/javascript',
    net_listening: true,
    eth_hashrate: '0x0',
    eth_mining: false,
    eth_syncing: true,
  }))

  // filters
  engine.addProvider(new FilterSubprovider())

  // vm
  engine.addProvider(new VmSubprovider())
github chronicled / open-registry-ethereum / backendSDK / lib / provider.js View on Github external
function Provider (rpcUrl, secretSeed) {
  var engine = new ProviderEngine();
  var web3 = new Web3(engine);
  
  engine.addProvider(new FixtureSubprovider({
    web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
    net_listening: true,
    eth_hashrate: '0x00',
    eth_mining: false,
    eth_syncing: true,
  }));

  // cache layer
  engine.addProvider(new CacheSubprovider());

  // filters 
  engine.addProvider(new FilterSubprovider())

  // pending nonce
  engine.addProvider(new NonceSubprovider());

  // vm
  //engine.addProvider(new VmSubprovider());

  if (secretSeed) {
    var ks = new wallet.keystore(secretSeed, pwDerivedKey);
    ks.generateNewAddress(pwDerivedKey, 1);
    var addr = '0x' + ks.getAddresses()[0];

    engine.addProvider(new HookedWalletSubprovider({
github trustwallet / trust-web3-provider / JS / src / index.js View on Github external
constructor(options, syncOptions) {
    super();
    const engine = this
    const web3 = new Web3(this)
    const { rpcUrl } = options

    context.web3 = web3
    globalSyncOptions = syncOptions

    engine.addProvider(new CacheSubprovider())
    engine.addProvider(new SubscriptionsSubprovider())
    engine.addProvider(new FilterSubprovider())
    engine.addProvider(hookedSubProvider = new HookedWalletSubprovider(options))
    engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcUrl)))
    engine.on('error', err => console.error(err.stack))
    engine.isTrust = true
    engine.start()
  }