Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Update fetch-and-compile readme with fetchAndCompileMultiple and getSupportedNetworks #4719

Merged
merged 5 commits into from
Feb 11, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion packages/fetch-and-compile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

This is used to obtain external verified sourced and compile them.

### Usage
Note: If you import this into your TS project, you may need to set `skipLibCheck` in your tsconfig due to an indirect dependency on @truffle/contract-schema.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set is ambiguous here, perhaps enable, or explicitly "set skipLibCheck to true"


## Usage

### `fetchAndCompile`

```ts
import * as dotenv from "dotenv";
Expand Down Expand Up @@ -65,5 +69,60 @@ async function decode(address: string) {
decode("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e");
```

### `fetchAndCompileMultiple`

If you want to fetch and compile multiple contracts from the same network, you can use `fetchAndCompileMultiple`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at this point we need to start introducing headings for each exposed interface, so that they remain visually separate. Would be nice also to have an upfront bulleted list at the top (with some preamble), linking to the individual headings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll go back and do that.


```ts
import { fetchAndCompileMultiple } from "@truffle/fetch-and-compile";
const config = /* set up config */;
const addresses: string[] = /* set addresses */;
const { results, failures } = await fetchAndCompileMultiple(addresses, config);
for (const address in results) {
const compileResult = results[address];
/* do things with compileResult as above */
}
for (const address in failures) {
/* do things with failed addresses */
}
```

### `getSupportedNetworks`

If you want a list of supported networks, you can call `getSupportedNetworks`:

```ts
import { getSupportedNetworks } from "@truffle/fetch-and-compile";
const networks = getSupportedNetworks();
// networks = {
// mainnet: {
// name: "mainnet",
// networkId: 1,
// chainId: 1,
// fetchers: ["etherscan", "sourcify"] //which fetchers support this network?
// },
// ...
//}
```

If you have a config with the `sourceFetchers` property set, you can call `getSupportedNetworks(config)`
and the output will be restricted to the networks supported by the fetchers listed there.

```ts
import { getSupportedNetworks } from "@truffle/fetch-and-compile";
import Config from "@truffle/config";
const config = Config.default().with({ sourceFetchers: ["etherscan"] });
const networks = getSupportedNetworks(config); //will only list those supported by etherscan fetcher
// networks = {
// mainnet: {
// name: "mainnet",
// networkId: 1,
// chainId: 1,
// fetchers: ["etherscan"] //sourcify is not listed since it's not being checked
// },
// ...
//}
```

Please see the [README for @truffle/decoder](https://github.com/trufflesuite/truffle/tree/develop/packages/decoder)
for more information on using Truffle decoder.