Skip to content

Instantly share code, notes, and snippets.

@pi0neerpat
Created March 26, 2020 15:48
Show Gist options
  • Save pi0neerpat/11a2a48a203172527db174a668385794 to your computer and use it in GitHub Desktop.
Save pi0neerpat/11a2a48a203172527db174a668385794 to your computer and use it in GitHub Desktop.
load wallet
async loadContracts({
walletProvider,
contractNames,
allowancesRequested,
balancesRequested,
}) {
console.log("lol")
try {
ethers.errors.setLogLevel("error") // "debug", "default", "info", "warn", "off"
const loadedContracts = {}
const { name: networkName } = await walletProvider.getNetwork()
contractNames.forEach(name => {
loadedContracts[name] = new ethers.Contract(
CONTRACTS[name][networkName],
CONTRACTS[name].abi,
walletProvider.getSigner()
)
})
const owner = await walletProvider
.listAccounts()
.then(accounts => accounts[0])
let allowancesObj
if (allowancesRequested) {
const allowances = await this.getAllowances({
contracts: loadedContracts,
owner,
allowancesRequested,
})
allowancesObj = allowances
}
const balances = await this.getBalances({
contracts: loadedContracts,
balancesRequested,
owner,
})
// eslint-disable-next-line no-console
console.log(
`Loaded contracts ${Object.keys(loadedContracts)} on ${networkName}`
)
return { contracts: loadedContracts, allowances: allowancesObj, balances }
} catch (error) {
return this.getErrorResponse(error, "loadContracts")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment