ethers.js/src.ts/providers/provider-etherscan.ts

32 lines
890 B
TypeScript
Raw Normal View History

2022-11-30 21:44:47 +03:00
/**
* Aboud Etherscan...
*
* @_subsection api/providers/thirdparty:Etherscan [etherscan]
*/
import { BaseEtherscanProvider } from "./provider-etherscan-base.js";
import { Contract } from "../contract/index.js";
2022-09-05 23:14:43 +03:00
function isPromise<T = any>(value: any): value is Promise<T> {
return (value && typeof(value.then) === "function");
2022-09-05 23:14:43 +03:00
}
2022-11-30 21:44:47 +03:00
/**
* Aboud EtherscanProvider...
*/
export class EtherscanProvider extends BaseEtherscanProvider {
async getContract(_address: string): Promise<null | Contract> {
let address = this._getAddress(_address);
if (isPromise(address)) { address = await address; }
2022-09-05 23:14:43 +03:00
try {
const resp = await this.fetch("contract", { action: "getabi", address });
const abi = JSON.parse(resp);
return new Contract(address, abi, this);
} catch (error) {
return null;
2022-09-05 23:14:43 +03:00
}
}
}