mirror of
https://github.com/tornadocash/provider.git
synced 2024-11-22 01:36:51 +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')
|
const { hexToNumberString, toChecksumAddress, numberToHex } = require('web3-utils')
|
||||||
|
|
||||||
export default (ctx, inject) => {
|
export default (ctx, inject) => {
|
||||||
// const moduleOptions = <%= JSON.stringify(options) %>
|
const moduleOptions = <%= JSON.stringify(options) %>
|
||||||
|
|
||||||
const instance = class Provider {
|
const instance = class Provider {
|
||||||
constructor(options) {
|
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 }) {
|
getContract({ abi, address }) {
|
||||||
return new this.web3.eth.Contract(abi, address)
|
return new this.web3.eth.Contract(abi, address)
|
||||||
}
|
}
|
||||||
|
3
types/index.d.ts
vendored
3
types/index.d.ts
vendored
@ -75,6 +75,7 @@ interface ProviderInstance {
|
|||||||
waitForTxReceipt(params: WaitForTxReceiptParams): Promise<TransactionReceipt>
|
waitForTxReceipt(params: WaitForTxReceiptParams): Promise<TransactionReceipt>
|
||||||
batchRequest(params: BatchRequestParams): Promise<string[]>
|
batchRequest(params: BatchRequestParams): Promise<string[]>
|
||||||
checkNetworkVersion(): Promise<string>
|
checkNetworkVersion(): Promise<string>
|
||||||
|
getWeb3(rpcUrl: string): Web3
|
||||||
on(params: OnListenerParams): void
|
on(params: OnListenerParams): void
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,4 +92,4 @@ declare module 'vue/types/vue' {
|
|||||||
interface Vue {
|
interface Vue {
|
||||||
$provider: ProviderInstance
|
$provider: ProviderInstance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user