implement ethers
MODIFY
package-lock.json
package-lock.json
{
"name": "@maticnetwork/maticjs",
- "version": "2.0.45",
+ "version": "3.0.0-beta.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@ethersproject/bytes": "^5.4.0"
}
},
+ "@ethersproject/basex": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/basex/-/basex-5.4.0.tgz",
+ "integrity": "sha512-J07+QCVJ7np2bcpxydFVf/CuYo9mZ7T73Pe7KQY4c1lRlrixMeblauMxHXD0MPwFmUHZIILDNViVkykFBZylbg==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0"
+ }
+ },
"@ethersproject/bignumber": {
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/@ethersproject/bignumber/-/bignumber-5.4.1.tgz",
"@ethersproject/bignumber": "^5.4.0"
}
},
+ "@ethersproject/contracts": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/contracts/-/contracts-5.4.1.tgz",
+ "integrity": "sha512-m+z2ZgPy4pyR15Je//dUaymRUZq5MtDajF6GwFbGAVmKz/RF+DNIPwF0k5qEcL3wPGVqUjFg2/krlCRVTU4T5w==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abi": "^5.4.0",
+ "@ethersproject/abstract-provider": "^5.4.0",
+ "@ethersproject/abstract-signer": "^5.4.0",
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/constants": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0"
+ },
+ "dependencies": {
+ "@ethersproject/abi": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.4.1.tgz",
+ "integrity": "sha512-9mhbjUk76BiSluiiW4BaYyI58KSbDMMQpCLdsAR+RsT2GyATiNYxVv+pGWRrekmsIdY3I+hOqsYQSTkc8L/mcg==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/constants": "^5.4.0",
+ "@ethersproject/hash": "^5.4.0",
+ "@ethersproject/keccak256": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0"
+ }
+ }
+ }
+ },
"@ethersproject/hash": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/hash/-/hash-5.4.0.tgz",
"@ethersproject/strings": "^5.4.0"
}
},
+ "@ethersproject/hdnode": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/hdnode/-/hdnode-5.4.0.tgz",
+ "integrity": "sha512-pKxdS0KAaeVGfZPp1KOiDLB0jba11tG6OP1u11QnYfb7pXn6IZx0xceqWRr6ygke8+Kw74IpOoSi7/DwANhy8Q==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abstract-signer": "^5.4.0",
+ "@ethersproject/basex": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/pbkdf2": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/sha2": "^5.4.0",
+ "@ethersproject/signing-key": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0",
+ "@ethersproject/wordlists": "^5.4.0"
+ }
+ },
+ "@ethersproject/json-wallets": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/json-wallets/-/json-wallets-5.4.0.tgz",
+ "integrity": "sha512-igWcu3fx4aiczrzEHwG1xJZo9l1cFfQOWzTqwRw/xcvxTk58q4f9M7cjh51EKphMHvrJtcezJ1gf1q1AUOfEQQ==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abstract-signer": "^5.4.0",
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/hdnode": "^5.4.0",
+ "@ethersproject/keccak256": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/pbkdf2": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/random": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0",
+ "aes-js": "3.0.0",
+ "scrypt-js": "3.0.1"
+ },
+ "dependencies": {
+ "aes-js": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.0.0.tgz",
+ "integrity": "sha1-4h3xCtbCBTKVvLuNq0Cwnb6ofk0=",
+ "dev": true
+ }
+ }
+ },
"@ethersproject/keccak256": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/keccak256/-/keccak256-5.4.0.tgz",
"@ethersproject/logger": "^5.4.0"
}
},
+ "@ethersproject/pbkdf2": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/pbkdf2/-/pbkdf2-5.4.0.tgz",
+ "integrity": "sha512-x94aIv6tiA04g6BnazZSLoRXqyusawRyZWlUhKip2jvoLpzJuLb//KtMM6PEovE47pMbW+Qe1uw+68ameJjB7g==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/sha2": "^5.4.0"
+ }
+ },
"@ethersproject/properties": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.4.0.tgz",
"@ethersproject/logger": "^5.4.0"
}
},
+ "@ethersproject/providers": {
+ "version": "5.4.5",
+ "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.4.5.tgz",
+ "integrity": "sha512-1GkrvkiAw3Fj28cwi1Sqm8ED1RtERtpdXmRfwIBGmqBSN5MoeRUHuwHPppMtbPayPgpFcvD7/Gdc9doO5fGYgw==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abstract-provider": "^5.4.0",
+ "@ethersproject/abstract-signer": "^5.4.0",
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/basex": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/constants": "^5.4.0",
+ "@ethersproject/hash": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/networks": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/random": "^5.4.0",
+ "@ethersproject/rlp": "^5.4.0",
+ "@ethersproject/sha2": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0",
+ "@ethersproject/web": "^5.4.0",
+ "bech32": "1.1.4",
+ "ws": "7.4.6"
+ },
+ "dependencies": {
+ "ws": {
+ "version": "7.4.6",
+ "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
+ "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
+ "dev": true
+ }
+ }
+ },
+ "@ethersproject/random": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/random/-/random-5.4.0.tgz",
+ "integrity": "sha512-pnpWNQlf0VAZDEOVp1rsYQosmv2o0ITS/PecNw+mS2/btF8eYdspkN0vIXrCMtkX09EAh9bdk8GoXmFXM1eAKw==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0"
+ }
+ },
"@ethersproject/rlp": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/rlp/-/rlp-5.4.0.tgz",
"@ethersproject/logger": "^5.4.0"
}
},
+ "@ethersproject/sha2": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/sha2/-/sha2-5.4.0.tgz",
+ "integrity": "sha512-siheo36r1WD7Cy+bDdE1BJ8y0bDtqXCOxRMzPa4bV1TGt/eTUUt03BHoJNB6reWJD8A30E/pdJ8WFkq+/uz4Gg==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "hash.js": "1.1.7"
+ }
+ },
"@ethersproject/signing-key": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/signing-key/-/signing-key-5.4.0.tgz",
}
}
},
+ "@ethersproject/solidity": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/solidity/-/solidity-5.4.0.tgz",
+ "integrity": "sha512-XFQTZ7wFSHOhHcV1DpcWj7VXECEiSrBuv7JErJvB9Uo+KfCdc3QtUZV+Vjh/AAaYgezUEKbCtE6Khjm44seevQ==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/keccak256": "^5.4.0",
+ "@ethersproject/sha2": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0"
+ }
+ },
"@ethersproject/strings": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/strings/-/strings-5.4.0.tgz",
"@ethersproject/signing-key": "^5.4.0"
}
},
+ "@ethersproject/units": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/units/-/units-5.4.0.tgz",
+ "integrity": "sha512-Z88krX40KCp+JqPCP5oPv5p750g+uU6gopDYRTBGcDvOASh6qhiEYCRatuM/suC4S2XW9Zz90QI35MfSrTIaFg==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/constants": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0"
+ }
+ },
+ "@ethersproject/wallet": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/wallet/-/wallet-5.4.0.tgz",
+ "integrity": "sha512-wU29majLjM6AjCjpat21mPPviG+EpK7wY1+jzKD0fg3ui5fgedf2zEu1RDgpfIMsfn8fJHJuzM4zXZ2+hSHaSQ==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abstract-provider": "^5.4.0",
+ "@ethersproject/abstract-signer": "^5.4.0",
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/hash": "^5.4.0",
+ "@ethersproject/hdnode": "^5.4.0",
+ "@ethersproject/json-wallets": "^5.4.0",
+ "@ethersproject/keccak256": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/random": "^5.4.0",
+ "@ethersproject/signing-key": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0",
+ "@ethersproject/wordlists": "^5.4.0"
+ }
+ },
"@ethersproject/web": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.4.0.tgz",
"@ethersproject/strings": "^5.4.0"
}
},
+ "@ethersproject/wordlists": {
+ "version": "5.4.0",
+ "resolved": "https://registry.npmjs.org/@ethersproject/wordlists/-/wordlists-5.4.0.tgz",
+ "integrity": "sha512-FemEkf6a+EBKEPxlzeVgUaVSodU7G0Na89jqKjmWMlDB0tomoU8RlEMgUvXyqtrg8N4cwpLh8nyRnm1Nay1isA==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/hash": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0"
+ }
+ },
"@maticnetwork/meta": {
"version": "2.4.18",
"resolved": "https://registry.npmjs.org/@maticnetwork/meta/-/meta-2.4.18.tgz",
}
}
},
+ "bech32": {
+ "version": "1.1.4",
+ "resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
+ "integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==",
+ "dev": true
+ },
"big.js": {
"version": "5.2.2",
"resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz",
}
}
},
+ "ethers": {
+ "version": "5.4.6",
+ "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.4.6.tgz",
+ "integrity": "sha512-F7LXARyB/Px3AQC6/QKedWZ8eqCkgOLORqL4B/F0Mag/K+qJSFGqsR36EaOZ6fKg3ZonI+pdbhb4A8Knt/43jQ==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/abi": "5.4.1",
+ "@ethersproject/abstract-provider": "5.4.1",
+ "@ethersproject/abstract-signer": "5.4.1",
+ "@ethersproject/address": "5.4.0",
+ "@ethersproject/base64": "5.4.0",
+ "@ethersproject/basex": "5.4.0",
+ "@ethersproject/bignumber": "5.4.1",
+ "@ethersproject/bytes": "5.4.0",
+ "@ethersproject/constants": "5.4.0",
+ "@ethersproject/contracts": "5.4.1",
+ "@ethersproject/hash": "5.4.0",
+ "@ethersproject/hdnode": "5.4.0",
+ "@ethersproject/json-wallets": "5.4.0",
+ "@ethersproject/keccak256": "5.4.0",
+ "@ethersproject/logger": "5.4.1",
+ "@ethersproject/networks": "5.4.2",
+ "@ethersproject/pbkdf2": "5.4.0",
+ "@ethersproject/properties": "5.4.1",
+ "@ethersproject/providers": "5.4.5",
+ "@ethersproject/random": "5.4.0",
+ "@ethersproject/rlp": "5.4.0",
+ "@ethersproject/sha2": "5.4.0",
+ "@ethersproject/signing-key": "5.4.0",
+ "@ethersproject/solidity": "5.4.0",
+ "@ethersproject/strings": "5.4.0",
+ "@ethersproject/transactions": "5.4.0",
+ "@ethersproject/units": "5.4.0",
+ "@ethersproject/wallet": "5.4.0",
+ "@ethersproject/web": "5.4.0",
+ "@ethersproject/wordlists": "5.4.0"
+ },
+ "dependencies": {
+ "@ethersproject/abi": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.4.1.tgz",
+ "integrity": "sha512-9mhbjUk76BiSluiiW4BaYyI58KSbDMMQpCLdsAR+RsT2GyATiNYxVv+pGWRrekmsIdY3I+hOqsYQSTkc8L/mcg==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/address": "^5.4.0",
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/constants": "^5.4.0",
+ "@ethersproject/hash": "^5.4.0",
+ "@ethersproject/keccak256": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/strings": "^5.4.0"
+ }
+ },
+ "@ethersproject/abstract-provider": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/abstract-provider/-/abstract-provider-5.4.1.tgz",
+ "integrity": "sha512-3EedfKI3LVpjSKgAxoUaI+gB27frKsxzm+r21w9G60Ugk+3wVLQwhi1LsEJAKNV7WoZc8CIpNrATlL1QFABjtQ==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/bignumber": "^5.4.0",
+ "@ethersproject/bytes": "^5.4.0",
+ "@ethersproject/logger": "^5.4.0",
+ "@ethersproject/networks": "^5.4.0",
+ "@ethersproject/properties": "^5.4.0",
+ "@ethersproject/transactions": "^5.4.0",
+ "@ethersproject/web": "^5.4.0"
+ }
+ },
+ "@ethersproject/logger": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/logger/-/logger-5.4.1.tgz",
+ "integrity": "sha512-DZ+bRinnYLPw1yAC64oRl0QyVZj43QeHIhVKfD/+YwSz4wsv1pfwb5SOFjz+r710YEWzU6LrhuSjpSO+6PeE4A==",
+ "dev": true
+ },
+ "@ethersproject/networks": {
+ "version": "5.4.2",
+ "resolved": "https://registry.npmjs.org/@ethersproject/networks/-/networks-5.4.2.tgz",
+ "integrity": "sha512-eekOhvJyBnuibfJnhtK46b8HimBc5+4gqpvd1/H9LEl7Q7/qhsIhM81dI9Fcnjpk3jB1aTy6bj0hz3cifhNeYw==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/logger": "^5.4.0"
+ }
+ },
+ "@ethersproject/properties": {
+ "version": "5.4.1",
+ "resolved": "https://registry.npmjs.org/@ethersproject/properties/-/properties-5.4.1.tgz",
+ "integrity": "sha512-cyCGlF8wWlIZyizsj2PpbJ9I7rIlUAfnHYwy/T90pdkSn/NFTa5YWZx2wTJBe9V7dD65dcrrEMisCRUJiq6n3w==",
+ "dev": true,
+ "requires": {
+ "@ethersproject/logger": "^5.4.0"
+ }
+ }
+ }
+ },
"ethjs-unit": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz",

MODIFY
package.json
package.json
"@typescript-eslint/parser": "^2.16.0",
"copy-webpack-plugin": "^6.1.1",
"cross-env": "^7.0.3",
+ "ethers": "^5.4.6",
"ganache-cli": "^6.12.1",
"husky": "2.4.1",
"lint-staged": "8.2.1",

MODIFY
src/abstracts/base_contract.ts
src/abstracts/base_contract.ts
import { BaseContractMethod } from "../abstracts";
+import { Logger } from "../utils";
export abstract class BaseContract {
- constructor(public address: string) {
+ constructor(public address: string, public logger:Logger) {
}

MODIFY
src/abstracts/base_web3_client.ts
src/abstracts/base_web3_client.ts
import { BaseContract } from "../abstracts";
import { ITransactionConfig, ITransactionReceipt, ITransactionData, IBlock, IBlockWithTransaction, IJsonRpcRequestPayload, IJsonRpcResponse } from "../interfaces";
+import { Logger } from "../utils";
export abstract class BaseWeb3Client {
- constructor(public provider: any) { }
+ constructor(public logger: Logger) {
+
+ }
abstract getContract(address: string, abi: any): BaseContract;

MODIFY
src/abstracts/contract_method.ts
src/abstracts/contract_method.ts
import { ITransactionConfig, ISendResult } from "../interfaces";
+import { Logger } from "../utils";
export abstract class BaseContractMethod {
+ constructor(public logger: Logger) {
+
+ }
abstract read<T>(tx?: ITransactionConfig,): Promise<T>;
abstract write(tx: ITransactionConfig,): ISendResult;
abstract estimateGas(tx: ITransactionConfig,): Promise<number>;

MODIFY
src/constant.ts
src/constant.ts
@@ -2,7 +2,7 @@ import { MaticWeb3Client } from "./web3js";
import { Logger } from "./utils";
import BN from "bn.js";
-export let Web3Client: typeof MaticWeb3Client = MaticWeb3Client;
+export let Web3Client = MaticWeb3Client;
export const setWeb3Client = (web3Client) => {
Web3Client = web3Client;

MODIFY
src/default.ts
src/default.ts
import { setWeb3Client, Web3Client } from "./constant";
import { PlasmaClient } from "./plasma";
import { POSClient } from "./pos";
-import { Web3Plugin } from "./plugins/plasma_web3_client";
import { use } from "./utils";
import { BaseWeb3Client } from "./abstracts";
@@ -10,10 +9,9 @@ export const defaultExport = {
setWeb3Client(client);
},
get Web3Client() {
- return Web3Client;
+ return Web3Client as any;
},
use: use,
PlasmaClient: PlasmaClient,
POSClient: POSClient,
- Web3Plugin: Web3Plugin,
}
\ No newline at end of file

ADD
src/ethers/ethjs_contract.ts
+import { BaseContract } from "../abstracts";
+import { Contract } from "ethers";
+import { ContractMethod } from "./ethjs_method";
+
+export class EthJsContract extends BaseContract {
+
+ contract: Contract;
+
+ constructor(address: string, contract: Contract, logger) {
+ super(address, logger);
+ this.contract = contract;
+ }
+
+ method(methodName: string, ...args) {
+ this.logger.log("args method", arguments);
+ return new ContractMethod(
+ this.logger, this.contract, methodName, args
+ );
+ }
+}
\ No newline at end of file

ADD
src/ethers/ethjs_method.ts
+import { BaseContractMethod } from "../abstracts";
+import { ContractFunction, Contract } from "ethers";
+import { ITransactionConfig, ISendResult } from "../interfaces";
+import { doNothing } from "../helpers";
+import { Logger } from "../utils";
+
+export class ContractMethod extends BaseContractMethod {
+ constructor(logger: Logger, private contract: Contract, private methodName, private args) {
+ super(logger);
+ }
+
+ encodeABI() {
+ return this.contract.interface.functions.encode[this.methodName](...this.args);
+ }
+
+ estimateGas(tx: ITransactionConfig) {
+ return this.contract.estimateGas[this.methodName](...this.args, tx).then(result => {
+ return result.toNumber();
+ });
+ }
+
+ read(config: ITransactionConfig) {
+ return this.getMethod_(config);
+ }
+
+ private getMethod_(config: ITransactionConfig) {
+ return this.contract[this.methodName](...this.args, config);
+ }
+
+ write(config: ITransactionConfig) {
+ const result = {
+ onTransactionHash: (doNothing as any),
+ onReceipt: doNothing,
+ onReceiptError: doNothing,
+ onTxError: doNothing
+ } as ISendResult;
+ this.getMethod_(config).then(tx => {
+ result.onTransactionHash(tx.transactionHash);
+ // wait for 10 sec for confirmation
+ // TODO - get the time from user
+ return tx.wait(10000);
+ }).then(receipt => {
+ result.onReceipt(receipt);
+ }).catch(err => {
+ result.onTxError(err);
+ result.onReceiptError(err);
+ });
+ return result;
+ }
+}
\ No newline at end of file

RENAME
src/plugins/plasma_web3_client.ts
src/ethers/index.ts
import { ITransactionConfig, IPlugin, ITransactionResult } from "../interfaces";
import { defaultExport } from "../default";
-import { MaticWeb3Client } from "../web3js";
+import { EtherWeb3Client } from "./web3_client";
-export class Web3Plugin implements IPlugin {
+export class EthersPlugin implements IPlugin {
setup(matic: typeof defaultExport) {
- matic.Web3Client = MaticWeb3Client;
+ matic.Web3Client = EtherWeb3Client as any;
}
}
\ No newline at end of file

ADD
src/ethers/web3_client.ts
+import { BaseWeb3Client } from "../abstracts";
+import { providers, Wallet, utils, Contract } from "ethers";
+import { IJsonRpcRequestPayload, ITransactionConfig } from "../interfaces";
+import { EthJsContract } from "./ethjs_contract";
+
+type ETHER_PROVIDER = providers.JsonRpcProvider;
+type ETHER_SIGNER = providers.JsonRpcSigner;
+
+export class EtherWeb3Client extends BaseWeb3Client {
+
+ provider: ETHER_PROVIDER;
+ signer: ETHER_SIGNER;
+
+ constructor(provider: ETHER_PROVIDER | Wallet, logger) {
+ super(logger);
+ if ((provider as ETHER_PROVIDER)._isProvider) {
+ this.provider = provider as ETHER_PROVIDER;
+ this.signer = this.provider.getSigner();
+ }
+ else {
+ this.signer = (provider as any);
+ this.provider = ((provider as Wallet).provider) as any;
+ }
+ }
+
+
+
+ getBlock(blockHashOrBlockNumber) {
+ return this.provider.getBlock(blockHashOrBlockNumber).then(block => {
+ return block as any;
+ });
+ }
+
+ getBlockWithTransaction(blockHashOrBlockNumber) {
+ return this.provider.getBlockWithTransactions(blockHashOrBlockNumber).then(block => {
+ return block as any;
+ });
+ }
+
+
+ getChainId() {
+ return this.signer.getChainId();
+ }
+
+ getTransaction(transactionHash: string) {
+ return this.provider.getTransaction(transactionHash).then(result => {
+ return result as any;
+ });
+ }
+
+ getTransactionCount(address: string, blockNumber: any) {
+ return this.provider.getTransactionCount(address, blockNumber);
+ }
+
+ getTransactionReceipt(transactionHash: string) {
+ return this.provider.getTransactionReceipt(transactionHash).then(result => {
+ return result as any;
+ });
+ }
+
+ getGasPrice() {
+ return this.provider.getGasPrice().then(result => {
+ return result.toString();
+ });
+ }
+
+ encodeParameters(params: any[], types: any[]) {
+ return utils.defaultAbiCoder.encode(types, params);
+ }
+
+ etheriumSha3(...value) {
+ return utils.keccak256(value);
+ }
+
+ sendRPCRequest(request: IJsonRpcRequestPayload) {
+ return this.provider.send(request.method, request.params);
+ }
+
+ private toTransactionRequest_(config: ITransactionConfig) {
+ return {
+ chainId: config.chainId,
+ data: config.data,
+ from: config.from as any,
+ gasLimit: config.gas,
+ gasPrice: config.gasPrice as any,
+ nonce: config.nonce,
+ to: config.to,
+ value: config.value as any
+ };
+ }
+
+ write(config: ITransactionConfig) {
+ return this.signer.sendTransaction(
+ this.toTransactionRequest_(config)
+ );
+ }
+
+ read(config: ITransactionConfig) {
+ return this.signer.call(
+ this.toTransactionRequest_(config)
+ );
+ }
+
+ getContract(address: string, abi: any) {
+ return new EthJsContract(
+ address,
+ new Contract(address, abi, this.signer),
+ this.logger
+ );
+ }
+}
\ No newline at end of file

MODIFY
src/index.ts
src/index.ts
@@ -8,6 +8,7 @@ export * from "./interfaces";
export * from "./types";
export * from "./constant";
export * from "./abstracts";
+export * from "./ethers";
export { initService } from "./services";
export default defaultExport;

MODIFY
src/utils/web3_side_chain_client.ts
src/utils/web3_side_chain_client.ts
@@ -27,8 +27,8 @@ export class Web3SideChainClient {
}
this.metaNetwork = metaNetwork;
- this.parent = new Web3Client(config.parent.provider);
- this.child = new Web3Client(config.child.provider);
+ this.parent = new Web3Client(config.parent.provider, this.logger);
+ this.child = new Web3Client(config.child.provider, this.logger);
// this.child.client.extend('bor', [
// {

MODIFY
src/web3js/eth_contract.ts
src/web3js/eth_contract.ts
@@ -5,15 +5,15 @@ import { EthMethod } from "./eth_method";
export class Web3Contract extends BaseContract {
contract: Contract;
- constructor(address: string, contract: Contract) {
- super(address);
+ constructor(address: string, contract: Contract, logger) {
+ super(address, logger);
this.contract = contract;
}
method(methodName: string, ...args) {
- console.log("args method", arguments);
+ this.logger.log("args method", arguments);
return new EthMethod(
- this.contract.methods[methodName](...args)
+ this.logger, this.contract.methods[methodName](...args)
);
}
}
\ No newline at end of file

MODIFY
src/web3js/eth_method.ts
src/web3js/eth_method.ts
@@ -3,11 +3,12 @@ import { ITransactionConfig } from "../interfaces";
import { TransactionObject } from "web3/eth/types";
import { doNothing } from "../helpers";
import { LOGGER } from "../constant";
+import { Logger } from "../utils";
export class EthMethod extends BaseContractMethod {
- constructor(private method: TransactionObject<any>) {
- super();
+ constructor(logger: Logger, private method: TransactionObject<any>) {
+ super(logger);
}
read<T>(tx: ITransactionConfig): Promise<T> {
@@ -23,27 +24,12 @@ export class EthMethod extends BaseContractMethod {
onTxError: doNothing
};
setTimeout(() => {
- LOGGER.log("sending tx with config", tx);
-
- // {
- // chainId: tx.chainId,
- // data: tx.data,
- // from: tx.from.toString(),
- // gas: tx.gas,
- // gasPrice: tx.gasPrice.toString(),
- // nonce: tx.nonce,
- // to: tx.to,
- // value: tx.value?.toString()
- // }
- // try {
+ this.logger.log("sending tx with config", tx);
this.method.send(tx as any).
once("transactionHash", result.onTransactionHash).
once("receipt", result.onReceipt).
on("error", result.onTxError).
on("error", result.onReceiptError);
- // } catch (error) {
-
- // }
}, 0);
return result;
}

MODIFY
src/web3js/web3_client.ts
src/web3js/web3_client.ts
@@ -4,12 +4,13 @@ import { ITransactionConfig, ITransactionData, ITransactionReceipt, IBlockWithTr
import { Transaction } from "web3/eth/types";
import { AbstractProvider } from "web3-core";
import { BaseWeb3Client } from "../abstracts";
+import { Logger } from "../utils";
export class MaticWeb3Client extends BaseWeb3Client {
private web3_: Web3;
- constructor(provider: any) {
- super(provider);
+ constructor(provider: any, logger: Logger) {
+ super(logger);
this.web3_ = new Web3(provider);
}
@@ -23,7 +24,7 @@ export class MaticWeb3Client extends BaseWeb3Client {
getContract(address: string, abi: any) {
const cont = new this.web3_.eth.Contract(abi, address);
- return new Web3Contract(address, cont as any);
+ return new Web3Contract(address, cont as any, this.logger);
}
getGasPrice() {

implement ethers