-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ecobioca/CeloscanProvider
Add CeloscanProvider
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from "./lib/CeloProvider"; | ||
export * from "./lib/CeloWallet"; | ||
export * from "./lib/StaticCeloProvider"; | ||
export * from "./lib/CeloscanProvider"; | ||
export * from "./lib/transactions"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { logger, providers, utils } from "ethers"; | ||
import { getNetwork } from "./networks"; | ||
|
||
export class CeloscanProvider extends providers.EtherscanProvider { | ||
constructor( | ||
networkish: providers.Networkish = 'celo', | ||
apiKey?: string | ||
) { | ||
const network = getNetwork(networkish); | ||
if (network == null) { | ||
return logger.throwError( | ||
`unknown network: ${JSON.stringify(network)}`, | ||
utils.Logger.errors.UNSUPPORTED_OPERATION, | ||
{ | ||
operation: 'getNetwork', | ||
value: networkish, | ||
}, | ||
); | ||
} | ||
super(network, apiKey); | ||
} | ||
|
||
getBaseUrl(): string { | ||
switch (this.network ? this.network.name : "invalid") { | ||
case "celo": | ||
return "https://api.celoscan.io"; | ||
case "alfajores": | ||
return "https://alfajores.celoscan.io"; | ||
case "baklava": | ||
// baklava is currently not supported by celoscan.io, so we use Blockscout | ||
return "https://explorer.celo.org/baklava"; | ||
default: | ||
}; | ||
|
||
return logger.throwArgumentError("unsupported network", "network", this.network.name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CeloscanProvider } from "../src/lib/CeloscanProvider"; | ||
|
||
async function main() { | ||
const account = process.env.ACCOUNT; | ||
if (!account) throw new Error("No ACCOUNT provided in env"); | ||
const network = process.env.NETWORK?.toLocaleLowerCase() || "celo"; | ||
console.info("Using CeloscanProvider with", network.toUpperCase(), "network"); | ||
const provider = new CeloscanProvider(network); | ||
const history = await provider.getHistory(account); | ||
console.info("Account", account, "history:"); | ||
console.info(history); | ||
} | ||
|
||
main() | ||
.then(() => console.info("Get history complete")) | ||
.catch(console.error); |