How to port from V5 to V6 for some TS code? #4115
Answered
by
ricmoo
zydjohnHotmail
asked this question in
Q&A
-
Ethers Version6.4.0 Search Termsproviders Describe the ProblemHi, Code Snippetimport { providers } from "ethers";
import {
ConnectionInfo
} from "ethers/lib/utils";
import { parseSignedTransaction } from "./helpers/utils";
export interface ClientVersion {
name: string,
version?: string,
major?: number,
minor?: number,
patch?: number,
system?: string,
}
export class QtumProvider extends providers.JsonRpcProvider {
constructor(
url?: ConnectionInfo | string,
network?: providers.Networkish
) {
super(url, network);
}
/**
* Override for QTUM parsing of transaction
* https://github.com/ethers-io/ethers.js/blob/master/packages/providers/src.ts/base-provider.ts
*/
async sendTransaction(
signedTransaction: string | Promise<string>
): Promise<providers.TransactionResponse> {
await this.getNetwork();
const signedTx = await Promise.resolve(signedTransaction);
const hexTx = `0x${signedTx}`;
// Parse the signed transaction here
const tx = parseSignedTransaction(signedTx);
try {
const hash = await this.perform("sendTransaction", {
signedTransaction: hexTx,
});
// Note: need to destructure return result here.
return this._wrapTransaction(tx, hash);
} catch (error) {
error.transaction = tx;
error.transactionHash = tx.hash;
throw error;
}
}
async isClientVersionGreaterThanEqualTo(major: number, minor: number, patch: number): Promise<boolean> {
const ver = await this.getClientVersion();
return compareVersion(ver, major, minor, patch) >= 0;
}
async getClientVersion(): Promise<ClientVersion> {
await this.getNetwork();
const version = await this.perform("web3_clientVersion", []);
if (version === "QTUM ETHTestRPC/ethereum-js") {
// 0.1.4, versions after this with a proper version string is 0.2.0
// this version contains a bug we have to work around
return {
name: "Janus",
version: "0.1.4",
major: 0,
minor: 1,
patch: 4,
system: "linux-amd64",
};
} else {
const versionInfo = version.split("/");
if (versionInfo.length >= 4) {
const semver = this.parseVersion(versionInfo[1]);
return {
name: versionInfo[0],
version: versionInfo[1],
major: semver[0] || 0,
minor: semver[1] || 0,
patch: semver[2] || 0,
system: versionInfo[2],
};
}
}
return {
name: version,
};
} Contract ABINo response Errors"ethers"' has no exported member named 'providers' Environmentnode.js (v12 or newer) Environment (Other)Windows 10 (version 22H2) with node.js version 20.2 |
Beta Was this translation helpful? Give feedback.
Answered by
ricmoo
Jun 2, 2023
Replies: 1 comment
-
All providers are offered on the root export, so you can use things like See the migration guide for more details. :) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ricmoo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
All providers are offered on the root export, so you can use things like
import { Networkish, JsonRpcProvider } from "ethers"
and such.See the migration guide for more details. :)