mirror of
https://github.com/tornadocash/provider.git
synced 2024-11-22 01:36:51 +01:00
feat: add init web3 method
This commit is contained in:
parent
0ab416ea58
commit
2649be0d65
@ -16,7 +16,6 @@ export default (ctx, inject) => {
|
||||
async initProvider(provider) {
|
||||
try {
|
||||
this.provider = provider
|
||||
// this.web3 = new Web3(provider)
|
||||
|
||||
await this._checkVersion()
|
||||
return await this._initProvider()
|
||||
@ -25,6 +24,21 @@ export default (ctx, inject) => {
|
||||
}
|
||||
}
|
||||
|
||||
initWeb3(rpcUrl) {
|
||||
try {
|
||||
if (!rpcUrl) {
|
||||
throw new Error(`Please set rpcUrl to params, current rpcUrl ${rpcUrl}`)
|
||||
}
|
||||
|
||||
const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl))
|
||||
this.web3 = web3
|
||||
|
||||
return web3
|
||||
} catch (err) {
|
||||
throw new Error(`Provider method initWeb3 has error: ${err.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
async sendRequest(params) {
|
||||
try {
|
||||
const request = (args) => (this.version === 'old' ? this._sendAsync(args) : this.provider.request(args))
|
||||
@ -182,7 +196,7 @@ export default (ctx, inject) => {
|
||||
const request = () =>
|
||||
this.version === 'old' ? this.provider.enable() : this.sendRequest({ method: 'eth_requestAccounts' })
|
||||
|
||||
const [account] = await request('')
|
||||
const [account] = await request()
|
||||
|
||||
if (!account) {
|
||||
throw new Error('Locked metamask')
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nuxtjs/provider",
|
||||
"version": "0.0.8",
|
||||
"version": "0.0.9",
|
||||
"description": "Provider integration with Nuxt.js",
|
||||
"repository": "provider-module",
|
||||
"license": "MIT",
|
||||
|
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@ -76,6 +76,8 @@ interface ProviderInstance {
|
||||
batchRequest(params: BatchRequestParams): Promise<string[]>
|
||||
checkNetworkVersion(): Promise<string>
|
||||
getWeb3(rpcUrl: string): Web3
|
||||
initWeb3(rpcUrl: string): Web3
|
||||
|
||||
on(params: OnListenerParams): void
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user