Skip to content

Commit eac0942

Browse files
committed
fix(connector-quorum): web3 Contract type usage
This was broken by an earlier commit: d75b9af Signed-off-by: Peter Somogyvari <[email protected]>
1 parent ec22a0f commit eac0942

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/cactus-plugin-ledger-connector-quorum/src/main/typescript/plugin-ledger-connector-quorum.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ import { Express } from "express";
55
import { promisify } from "util";
66
import { Optional } from "typescript-optional";
77
import Web3 from "web3";
8-
9-
import { Contract, ContractSendMethod } from "web3-eth-contract";
8+
// The strange way of obtaining the contract class here is like this because
9+
// web3-eth internally sub-classes the Contract class at runtime
10+
// @see https://stackoverflow.com/a/63639280/698470
11+
const Contract = new Web3().eth.Contract;
12+
import { ContractSendMethod } from "web3-eth-contract";
1013
import { TransactionReceipt } from "web3-eth";
1114

1215
import {
@@ -83,7 +86,8 @@ export class PluginLedgerConnectorQuorum
8386
private readonly web3: Web3;
8487
private httpServer: Server | SecureServer | null = null;
8588
private contracts: {
86-
[name: string]: Contract;
89+
// @see https://stackoverflow.com/a/63639280/698470
90+
[name: string]: InstanceType<typeof Contract>;
8791
} = {};
8892

8993
private endpoints: IWebServiceEndpoint[] | undefined;
@@ -227,7 +231,7 @@ export class PluginLedgerConnectorQuorum
227231
}
228232

229233
const { contractAddress } = req;
230-
const aContract = new Contract(abi, contractAddress);
234+
const aContract = new this.web3.eth.Contract(abi, contractAddress);
231235
const methodRef = aContract.methods[req.methodName];
232236

233237
Checks.truthy(methodRef, `${fnTag} YourContract.${req.methodName}`);
@@ -320,7 +324,7 @@ export class PluginLedgerConnectorQuorum
320324
contractJSON.networks = network;
321325
keychainPlugin.set(contractName, contractJSON);
322326
}
323-
const contract = new Contract(
327+
const contract = new this.web3.eth.Contract(
324328
contractJSON.abi,
325329
contractJSON.networks[networkId].address,
326330
);
@@ -575,7 +579,7 @@ export class PluginLedgerConnectorQuorum
575579
req.contractName,
576580
)) as any;
577581
this.log.info(JSON.stringify(contractJSON));
578-
const contract = new Contract(
582+
const contract = new this.web3.eth.Contract(
579583
contractJSON.abi,
580584
receipt.transactionReceipt.contractAddress,
581585
);

0 commit comments

Comments
 (0)