2022-11-30 23:44:23 +03:00
|
|
|
/**
|
2023-01-28 09:53:29 +03:00
|
|
|
* [[link-etherscan]] provides a third-party service for connecting to
|
|
|
|
* various blockchains over a combination of JSON-RPC and custom API
|
|
|
|
* endpoints.
|
2022-11-30 23:44:23 +03:00
|
|
|
*
|
2023-01-28 09:53:29 +03:00
|
|
|
* **Supported Networks**
|
|
|
|
*
|
|
|
|
* - Ethereum Mainnet (``mainnet``)
|
|
|
|
* - Goerli Testnet (``goerli``)
|
|
|
|
* - Sepolia Testnet (``sepolia``)
|
|
|
|
* - Arbitrum (``arbitrum``)
|
|
|
|
* - Arbitrum Goerli Testnet (``arbitrum-goerli``)
|
|
|
|
* - Optimism (``optimism``)
|
|
|
|
* - Optimism Goerli Testnet (``optimism-goerli``)
|
|
|
|
* - Polygon (``matic``)
|
|
|
|
* - Polygon Mumbai Testnet (``maticmum``)
|
|
|
|
*
|
|
|
|
* @_subsection api/providers/thirdparty:Etherscan [providers-etherscan]
|
2022-11-30 23:44:23 +03:00
|
|
|
*/
|
2022-09-27 10:45:27 +03:00
|
|
|
import { BaseEtherscanProvider } from "./provider-etherscan-base.js";
|
|
|
|
import { Contract } from "../contract/index.js";
|
|
|
|
function isPromise(value) {
|
|
|
|
return (value && typeof (value.then) === "function");
|
2022-09-05 23:57:11 +03:00
|
|
|
}
|
2022-11-30 23:44:23 +03:00
|
|
|
/**
|
2023-01-28 09:53:29 +03:00
|
|
|
* The **EtherscanProvider** connects to the [[link-etherscan]]
|
|
|
|
* JSON-RPC end-points.
|
|
|
|
*
|
|
|
|
* By default, requests are highly-throttled, which is
|
|
|
|
* appropriate for quick prototypes and simple scripts. To
|
|
|
|
* gain access to an increased rate-limit, it is highly
|
|
|
|
* recommended to [sign up here](link-etherscan-signup).
|
2022-11-30 23:44:23 +03:00
|
|
|
*/
|
2022-09-27 10:45:27 +03:00
|
|
|
export class EtherscanProvider extends BaseEtherscanProvider {
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* Resolves to a [Contract]] for %%address%%, using the
|
|
|
|
* Etherscan API to retreive the Contract ABI.
|
|
|
|
*/
|
2022-09-27 10:45:27 +03:00
|
|
|
async getContract(_address) {
|
|
|
|
let address = this._getAddress(_address);
|
|
|
|
if (isPromise(address)) {
|
|
|
|
address = await address;
|
2022-09-05 23:57:11 +03:00
|
|
|
}
|
2022-09-27 10:45:27 +03:00
|
|
|
try {
|
|
|
|
const resp = await this.fetch("contract", { action: "getabi", address });
|
|
|
|
const abi = JSON.parse(resp);
|
|
|
|
return new Contract(address, abi, this);
|
2022-09-05 23:57:11 +03:00
|
|
|
}
|
2022-09-27 10:45:27 +03:00
|
|
|
catch (error) {
|
|
|
|
return null;
|
2022-09-05 23:57:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//# sourceMappingURL=provider-etherscan.js.map
|