Merge branch 'master' into deactivatewallet

pull/3710/head
David Disu 2 years ago committed by GitHub
commit 6f19529e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/etherscan/src/app/RemixPlugin.tsx
  2. 4
      apps/etherscan/src/app/app.tsx
  3. 2
      apps/etherscan/src/app/routes.tsx
  4. 33
      apps/etherscan/src/app/utils/networks.ts
  5. 24
      apps/etherscan/src/app/utils/utilities.ts
  6. 4
      apps/etherscan/src/app/utils/verify.ts
  7. 4
      apps/etherscan/src/app/views/ReceiptsView.tsx
  8. 2
      apps/etherscan/src/app/views/VerifyView.tsx
  9. 4
      apps/etherscan/src/profile.json

@ -16,11 +16,11 @@ export class RemixClient extends PluginClient {
async receiptStatus (receiptGuid: string, apiKey: string) { async receiptStatus (receiptGuid: string, apiKey: string) {
try { try {
const network = await getNetworkName(this) const { network, networkId } = await getNetworkName(this)
if (network === "vm") { if (network === "vm") {
throw new Error("Cannot check the receipt status in the selected network") throw new Error("Cannot check the receipt status in the selected network")
} }
const etherscanApi = getEtherScanApi(network) const etherscanApi = getEtherScanApi(network, networkId)
const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi) const receiptStatus = await getReceiptStatus(receiptGuid, apiKey, etherscanApi)
return { return {
message: receiptStatus.result, message: receiptStatus.result,

@ -94,14 +94,14 @@ const App = () => {
if (!clientInstanceRef.current) { if (!clientInstanceRef.current) {
return {} return {}
} }
const network = await getNetworkName(clientInstanceRef.current) const { network, networkId } = await getNetworkName(clientInstanceRef.current)
if (network === "vm") { if (network === "vm") {
return {} return {}
} }
const status = await getReceiptStatus( const status = await getReceiptStatus(
item.guid, item.guid,
apiKey, apiKey,
getEtherScanApi(network) getEtherScanApi(network, networkId)
) )
if (status.result === "Pass - Verified" || status.result === "Already Verified") { if (status.result === "Pass - Verified" || status.result === "Already Verified") {
const newReceipts = receipts.map((currentReceipt: Receipt) => { const newReceipts = receipts.map((currentReceipt: Receipt) => {

@ -43,7 +43,7 @@ export const DisplayRoutes = () => (
</DefaultLayout>} /> </DefaultLayout>} />
<Route <Route
path="/settings" path="/settings"
element={<DefaultLayout from="/settings" title="Set Etherscan API Key"> element={<DefaultLayout from="/settings" title="Set Explorer API Key">
<CaptureKeyView /> <CaptureKeyView />
</DefaultLayout>} /> </DefaultLayout>} />
</Routes> </Routes>

@ -0,0 +1,33 @@
export const scanAPIurls = {
// all mainnet
56: "https://api.bscscan.com/api",
137: "https://api.polygonscan.com/api",
250: "https://api.ftmscan.com/api",
42161: "https://api.arbiscan.io/api",
43114: "https://api.snowtrace.io/api",
1285: "https://api-moonriver.moonscan.io/api",
1284: "https://api-moonbeam.moonscan.io/api",
25: "https://api.cronoscan.com/api",
199: "https://api.bttcscan.com/api",
10: "https://api-optimistic.etherscan.io/api",
42220: "https://api.celoscan.io/api",
288: "https://api.bobascan.com/api",
100: "https://api.gnosisscan.io/api",
1101: "https://api-zkevm.polygonscan.com/api",
// all testnet
97: "https://api-testnet.bscscan.com/api",
80001: "https://api-testnet.polygonscan.com/api",
4002: "https://api-testnet.ftmscan.com/api",
421611: "https://api-testnet.arbiscan.io/api",
42170: "https://api-nova.arbiscan.io/api",
43113: "https://api-testnet.snowtrace.io/api",
1287: "https://api-moonbase.moonscan.io/api",
338: "https://api-testnet.cronoscan.com/api",
1028: "https://api-testnet.bttcscan.com/api",
420: "https://api-goerli-optimistic.etherscan.io/api",
44787: "https://api-alfajores.celoscan.io/api",
2888: "https://api-testnet.bobascan.com/api",
84531: "https://api-goerli.basescan.org/api",
1442: "https://api-testnet-zkevm.polygonscan.com/api"
}

@ -1,5 +1,6 @@
import { PluginClient } from "@remixproject/plugin" import { PluginClient } from "@remixproject/plugin"
import axios from 'axios' import axios from 'axios'
import { scanAPIurls } from "./networks"
type RemixClient = PluginClient type RemixClient = PluginClient
/* /*
@ -13,18 +14,29 @@ export type receiptStatus = {
status: string status: string
} }
export const getEtherScanApi = (network: string) => { export const getEtherScanApi = (network: string, networkId: any) => {
return network === "main" let apiUrl
? `https://api.etherscan.io/api`
: `https://api-${network}.etherscan.io/api` if (network === "main") {
apiUrl = "https://api.etherscan.io/api"
} else if (network === "custom") {
if (!(networkId in scanAPIurls)) {
throw new Error("no known network to verify against")
}
apiUrl = (scanAPIurls as any)[networkId]
} else {
apiUrl = `https://api-${network}.etherscan.io/api`
}
return apiUrl
} }
export const getNetworkName = async (client: RemixClient) => { export const getNetworkName = async (client: RemixClient) => {
const network = await client.call("network", "detectNetwork") const network = await client.call("network", "detectNetwork")
if (!network) { if (!network) {
throw new Error("no known network to verify against") throw new Error("no known network to verify against")
} }
return network.name!.toLowerCase() return { network: network.name!.toLowerCase(), networkId: network.id }
} }
export const getReceiptStatus = async ( export const getReceiptStatus = async (

@ -25,14 +25,14 @@ export const verify = async (
onVerifiedContract: (value: EtherScanReturn) => void, onVerifiedContract: (value: EtherScanReturn) => void,
setResults: (value: string) => void setResults: (value: string) => void
) => { ) => {
const network = await getNetworkName(client) const { network, networkId } = await getNetworkName(client)
if (network === "vm") { if (network === "vm") {
return { return {
succeed: false, succeed: false,
message: "Cannot verify in the selected network" message: "Cannot verify in the selected network"
} }
} }
const etherscanApi = getEtherScanApi(network) const etherscanApi = getEtherScanApi(network, networkId)
try { try {
const contractMetadata = getContractMetadata( const contractMetadata = getContractMetadata(

@ -19,7 +19,7 @@ export const ReceiptsView: React.FC = () => {
apiKey: string apiKey: string
) => { ) => {
try { try {
const network = await getNetworkName(clientInstance) const { network, networkId } = await getNetworkName(clientInstance)
if (network === "vm") { if (network === "vm") {
setResults({ setResults({
succeed: false, succeed: false,
@ -27,7 +27,7 @@ export const ReceiptsView: React.FC = () => {
}) })
return return
} }
const etherscanApi = getEtherScanApi(network) const etherscanApi = getEtherScanApi(network, networkId)
const result = await getReceiptStatus( const result = await getReceiptStatus(
values.receiptGuid, values.receiptGuid,
apiKey, apiKey,

@ -38,7 +38,7 @@ export const VerifyView: React.FC<Props> = ({
useEffect(() => { useEffect(() => {
if (client && client.on) { if (client && client.on) {
client.on("blockchain" as any, 'networkStatus', (result) => { client.on("blockchain" as any, 'networkStatus', (result) => {
setNetworkName(result.network.name) setNetworkName(`${result.network.name} (Chain id: ${result.network.id})`)
}) })
} }
return () => { return () => {

@ -1,7 +1,7 @@
{ {
"name": "etherscan", "name": "etherscan",
"displayName": "Etherscan - Contract verification", "displayName": "Contract verification - Etherscan",
"description": "Verify Solidity contract code using Etherscan API", "description": "Verify Solidity contract code using Etherscan, BscScan, PolygonScan etc. APIs",
"version": "0.1.0", "version": "0.1.0",
"events": [], "events": [],
"methods": ["verify", "receiptStatus"], "methods": ["verify", "receiptStatus"],

Loading…
Cancel
Save