Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if(!privateKey) {
privateKey = Wallet.generate().getPrivateKeyString().slice(2);
if(localStorage) {
localStorage.setItem("localPrivateKey", privateKey)}
}
// This uses web3-provider-engine and ethereumjs-wallet to construct a
// wallet in-browser, without needing Metamask, Toshi, etc.
//
// Note that the current version of ethereumjs-wallet on npm has a bug,
// but the latest on Github works just fine.
var wallet = Wallet.fromPrivateKey(new Buffer(privateKey, "hex"));
this.engine = new ProviderEngine();
this.web3 = new Web3(this.engine);
console.log(this.web3)
// static results
this.engine.addProvider(new FixtureSubprovider({
web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
net_listening: true,
eth_hashrate: '0x00',
eth_mining: false,
eth_syncing: true,
}))
// filters
this.engine.addProvider(new FilterSubprovider())
// id mgmt
this.engine.addProvider(new WalletSubprovider(wallet, {}))
this.engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcURL)));
this.engine.on('block', function(block) {
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())
// id mgmt
engine.addProvider(new HookedWalletSubprovider({
getAccounts: opts.getAccounts,
this.web3 = new Web3(options.currentProvider);
} else if (window && window.web3) {
this.web3 = new Web3(window.web3.currentProvider);
} else {
var privateKey = options.privateKey || localStorage.getItem("localPrivateKey");
if (!privateKey) {
privateKey = Wallet.generate().getPrivateKeyString().slice(2);
if (localStorage) {
localStorage.setItem("localPrivateKey", privateKey);
}
}
var wallet = Wallet.fromPrivateKey(new Buffer(privateKey, "hex"));
this.engine = new ProviderEngine();
this.web3 = new Web3(this.engine);
// static results
this.engine.addProvider(new FixtureSubprovider({
web3_clientVersion: 'ProviderEngine/v0.0.0/javascript',
net_listening: true,
eth_hashrate: '0x00',
eth_mining: false,
eth_syncing: true
}));
// filters
this.engine.addProvider(new FilterSubprovider());
// id mgmt
this.engine.addProvider(new WalletSubprovider(wallet, {}));
this.engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(rpcURL)));
this.engine.on('block', function (block) {
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());