mirror of
https://github.com/tornadocash/provider.git
synced 2024-11-22 09:46:52 +01:00
feat: getter for web3
This commit is contained in:
parent
7d17901c61
commit
418d238b01
@ -2,7 +2,7 @@ const Web3 = require('web3')
|
||||
const { hexToNumberString, toChecksumAddress, numberToHex } = require('web3-utils')
|
||||
|
||||
export default (ctx, inject) => {
|
||||
// const moduleOptions = <%= JSON.stringify(options) %>
|
||||
const moduleOptions = <%= JSON.stringify(options) %>
|
||||
|
||||
const instance = class Provider {
|
||||
constructor(options) {
|
||||
@ -35,6 +35,18 @@ export default (ctx, inject) => {
|
||||
}
|
||||
}
|
||||
|
||||
getWeb3(rpcUrl) {
|
||||
try {
|
||||
if (!url) {
|
||||
throw new Error(`Please set url to params, current url ${rpcUrl}`)
|
||||
}
|
||||
|
||||
return new Web3(rpcUrl)
|
||||
} catch (err) {
|
||||
throw new Error(`Provider method getWeb3 has error: ${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
getContract({ abi, address }) {
|
||||
return new this.web3.eth.Contract(abi, address)
|
||||
}
|
||||
|
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
@ -75,6 +75,7 @@ interface ProviderInstance {
|
||||
waitForTxReceipt(params: WaitForTxReceiptParams): Promise<TransactionReceipt>
|
||||
batchRequest(params: BatchRequestParams): Promise<string[]>
|
||||
checkNetworkVersion(): Promise<string>
|
||||
getWeb3(rpcUrl: string): Web3
|
||||
on(params: OnListenerParams): void
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user