This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update fetch-and-compile readme with fetchAndCompileMultiple and getSupportedNetworks #4719
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ceb9f1
Update fetch-and-compile readme with fetchAndCompileMultiple and getS…
haltman-at be937c4
Add headers for exported functions
haltman-at 26c654a
Add note about skipLibCheck
haltman-at 62976af
Adjust headers
haltman-at 274a177
Clarify wording about configuration
haltman-at File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
## Usage | ||
|
||
### `fetchAndCompile` | ||
|
||
```ts | ||
import * as dotenv from "dotenv"; | ||
|
@@ -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`: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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"