diff --git a/package.json b/package.json index 3ef9165..8c8e1a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maticnetwork/maticjs-ethers", - "version": "1.0.3", + "version": "1.1.0", "description": "ethers plugin for matic.js", "main": "dist/npm.export.js", "types": "dist/ts/index.d.ts", diff --git a/src/ethers/web3_client.ts b/src/ethers/web3_client.ts index 60ecb82..93679d0 100644 --- a/src/ethers/web3_client.ts +++ b/src/ethers/web3_client.ts @@ -6,29 +6,28 @@ import { ethBlockToMaticBlock, ethReceiptToMaticReceipt, ethTxToMaticTx } from " type ETHER_PROVIDER = providers.JsonRpcProvider; type ETHER_SIGNER = providers.JsonRpcSigner; +type WEB3_PROVIDER = providers.Web3Provider; export class EtherWeb3Client extends BaseWeb3Client { name = 'ETHER'; provider: ETHER_PROVIDER; signer: ETHER_SIGNER; - constructor(provider: ETHER_PROVIDER | Wallet, logger) { + constructor(provider: ETHER_PROVIDER | Wallet | WEB3_PROVIDER, logger) { super(logger); - if ((provider as ETHER_PROVIDER)._isProvider) { - this.provider = provider as ETHER_PROVIDER; - this.signer = this.provider.getSigner(); - if (!this.signer || !this.signer._address) { - this.signer = (provider as any); - } - } - else { - this.signer = (provider as any); - this.provider = ((provider as Wallet).provider) as any; + + if (provider instanceof ethers.providers.Web3Provider) { + this.provider = provider; + this.signer = provider.getSigner(); + } else if (provider instanceof ethers.providers.JsonRpcProvider) { + this.provider = provider; + this.signer = provider as any; + } else { + this.signer = provider as any; + this.provider = provider.provider || provider as any; } } - - getBlock(blockHashOrBlockNumber) { return this.provider.getBlock(blockHashOrBlockNumber).then(block => { return block as any; @@ -57,7 +56,9 @@ export class EtherWeb3Client extends BaseWeb3Client { getChainId() { - return this.signer.getChainId(); + return this.provider.getNetwork().then(function (res) { + return res.chainId; + }); } getBalance(address) {