Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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('================================')
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())
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({
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()
}