Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function provider(): ethers.providers.JsonRpcProvider {
const providerEngine = new Web3ProviderEngine()
providerEngine.addProvider(new FakeGasEstimateSubprovider(5 * 10 ** 6)) // Ganache does a poor job of estimating gas, so just crank it up for testing.
if (process.env.DEBUG) {
debug('Debugging enabled, using sol-trace module...')
const defaultFromAddress = ''
const artifactAdapter = new SolCompilerArtifactAdapter(
path.resolve('dist/artifacts'),
path.resolve('contracts'),
)
const revertTraceSubprovider = new RevertTraceSubprovider(
artifactAdapter,
defaultFromAddress,
true,
)
providerEngine.addProvider(revertTraceSubprovider)
}
).getAddress()
console.log(
chalk.green(
'Default from address derived from mnemonic:',
defaultFromAddress,
),
)
const artifactAdapter = new SolCompilerArtifactAdapter(artifacts, contracts)
const revertTraceSubprovider = new RevertTraceSubprovider(
artifactAdapter,
defaultFromAddress,
true,
)
const providerEngine = new Web3ProviderEngine()
providerEngine.addProvider(new FakeGasEstimateSubprovider(4 * 10 ** 6)) // Ganache does a poor job of estimating gas, so just crank it up for testing.
providerEngine.addProvider(revertTraceSubprovider)
providerEngine.addProvider(
// Start an in-process ganache instance
new GanacheSubprovider({
mnemonic,
hdPath: path,
vmErrorsOnRPCResponse: true,
}),
)
providerEngine.start()
const provider = new ethers.providers.Web3Provider(providerEngine)
const accounts = await provider.listAccounts()
console.log(chalk.green(`Accounts from provider: ${accounts}`))