pub enum Source {
Local(PathBuf),
Http(Url),
Etherscan(Address),
Npm(String),
}
Expand description
A source of an artifact JSON.
Variants§
Local(PathBuf)
File on the local file system.
Http(Url)
Resource in the internet, available via HTTP(S).
Etherscan(Address)
An address of a mainnet contract, available via Etherscan.
Artifacts loaded from etherstan can be parsed using the truffle loader.
Note that Etherscan rate-limits requests to their API, to avoid this,
provide an Etherscan API key via the ETHERSCAN_API_KEY
environment variable.
Npm(String)
The package identifier of an NPM package with a path to an artifact or ABI to be retrieved from unpkg.
Implementations§
Source§impl Source
impl Source
Sourcepub fn parse(source: &str) -> Result<Self>
pub fn parse(source: &str) -> Result<Self>
Parses an artifact source from a string.
This method accepts the following:
-
relative path to a contract JSON file on the local filesystem, for example
build/IERC20.json
. This relative path is rooted in the current working directory. To specify the root for relative paths, use [with_root
] function; -
absolute path to a contract JSON file on the local filesystem, or a file URL, for example
/build/IERC20.json
, or the same path using URL:file:///build/IERC20.json
; -
an HTTP(S) URL pointing to artifact JSON or contract ABI JSON;
-
a URL with
etherscan
scheme and a mainnet contract address. For exampleetherscan:0xC02AA...
. Alternatively, specify an etherscan URL:https://etherscan.io/address/0xC02AA...
. The contract artifact or ABI will be retrieved through [Etherscan
]; -
a URL with
npm
scheme, NPM package name, an optional version and a path (defaulting to the latest version andindex.js
). For examplenpm:@openzeppelin/contracts/build/contracts/IERC20.json
. The contract artifact or ABI will be retrieved through [unpkg
].
Sourcepub fn with_root(root: impl AsRef<Path>, source: &str) -> Result<Self>
pub fn with_root(root: impl AsRef<Path>, source: &str) -> Result<Self>
Parses an artifact source from a string and uses the specified root
directory for resolving relative paths. See [parse
] for more details
on supported source strings.
Sourcepub fn local(path: impl AsRef<Path>) -> Self
pub fn local(path: impl AsRef<Path>) -> Self
Creates a local filesystem source from a path string.
Sourcepub fn etherscan(address: &str) -> Result<Self>
pub fn etherscan(address: &str) -> Result<Self>
Creates an Etherscan source from contract address on mainnet.
Sourcepub fn artifact_json(&self) -> Result<String>
pub fn artifact_json(&self) -> Result<String>
Retrieves the source JSON of the artifact.
This will either read the JSON from the file system or retrieve a contract ABI from the network, depending on the source type.
Contract ABIs will be wrapped into a JSON object, so that you can load them using the truffle loader.