@@ -5,8 +5,11 @@ import { Express } from "express";
5
5
import { promisify } from "util" ;
6
6
import { Optional } from "typescript-optional" ;
7
7
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" ;
10
13
import { TransactionReceipt } from "web3-eth" ;
11
14
12
15
import {
@@ -83,7 +86,8 @@ export class PluginLedgerConnectorQuorum
83
86
private readonly web3 : Web3 ;
84
87
private httpServer : Server | SecureServer | null = null ;
85
88
private contracts : {
86
- [ name : string ] : Contract ;
89
+ // @see https://stackoverflow.com/a/63639280/698470
90
+ [ name : string ] : InstanceType < typeof Contract > ;
87
91
} = { } ;
88
92
89
93
private endpoints : IWebServiceEndpoint [ ] | undefined ;
@@ -227,7 +231,7 @@ export class PluginLedgerConnectorQuorum
227
231
}
228
232
229
233
const { contractAddress } = req ;
230
- const aContract = new Contract ( abi , contractAddress ) ;
234
+ const aContract = new this . web3 . eth . Contract ( abi , contractAddress ) ;
231
235
const methodRef = aContract . methods [ req . methodName ] ;
232
236
233
237
Checks . truthy ( methodRef , `${ fnTag } YourContract.${ req . methodName } ` ) ;
@@ -320,7 +324,7 @@ export class PluginLedgerConnectorQuorum
320
324
contractJSON . networks = network ;
321
325
keychainPlugin . set ( contractName , contractJSON ) ;
322
326
}
323
- const contract = new Contract (
327
+ const contract = new this . web3 . eth . Contract (
324
328
contractJSON . abi ,
325
329
contractJSON . networks [ networkId ] . address ,
326
330
) ;
@@ -575,7 +579,7 @@ export class PluginLedgerConnectorQuorum
575
579
req . contractName ,
576
580
) ) as any ;
577
581
this . log . info ( JSON . stringify ( contractJSON ) ) ;
578
- const contract = new Contract (
582
+ const contract = new this . web3 . eth . Contract (
579
583
contractJSON . abi ,
580
584
receipt . transactionReceipt . contractAddress ,
581
585
) ;
0 commit comments