Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(async (resolve, reject) => {
// for modern dapp browsers
// if (this.address && !ethereum && !web3 && !web3.currentProvider) {
if (this.address) {
const engine = new ProviderEngine();
Web3.providers.HttpProvider.prototype.sendAsync =
Web3.providers.HttpProvider.prototype.send;
if (!this.watchOnly) {
engine.addProvider(new WalletSubprovider(this.instanceWallet, {}));
}
engine.addProvider(
new RpcSubprovider({
rpcUrl: this.networkUrl
})
);
engine.start();
this.web3 = new Web3(engine);
this.web3.eth.defaultAccount = this.getAddress();
resolve();
return;
}
if (ethereum) {
static getWeb3Instance() {
const wallet = this.getWallet();
const engine = new ProviderEngine();
engine.addProvider(new WalletSubprovider(wallet, {}));
engine.addProvider(new ProviderSubprovider(this.getWeb3HTTPProvider()));
engine.start();
const web3 = new Web3(engine);
web3.eth.defaultAccount = wallet.getAddressString();
return web3;
}
export const getWeb3FromWalletWithMneumonic = () => {
const engine = new ProviderEngine()
const mneumonic = TransmuteCrypto.generateMnemonic()
const wallet = TransmuteCrypto.getWalletFromMnemonic(mneumonic)
const address = TransmuteCrypto.getDefaultAddressFromWallet(wallet)
engine.addProvider(new WalletSubprovider(wallet, {}))
engine.addProvider(
new RpcSubprovider({
rpcUrl: RPC_HOST
})
)
engine.start()
return {
web3: new Web3(engine),
address
}
}
export const getWeb3FromWalletWithPrivateKey = async () => {
const engine = new ProviderEngine()
const sodium = await TransmuteCrypto.getSodium()
const alice = sodium.crypto_box_keypair()
const unPrefixedPrivateKeyHexString = sodium.to_hex(alice.privateKey)
const wallet = TransmuteCrypto.getWalletFromPrivateKey(unPrefixedPrivateKeyHexString)
const address = TransmuteCrypto.getDefaultAddressFromWallet(wallet)
engine.addProvider(new WalletSubprovider(wallet, {}))
engine.addProvider(
new RpcSubprovider({
rpcUrl: RPC_HOST
})
)
engine.start()
return {
web3: new Web3(engine),
address
}
}