Skip to content

Commit

Permalink
fix: signer
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinmittal23 committed Mar 8, 2024
1 parent 4bfe2b6 commit 03f7e19
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
29 changes: 15 additions & 14 deletions src/ethers/web3_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 03f7e19

Please sign in to comment.