EIPs Explained

ERC-2942 · Stagnant · ERC · 2020-09-04

ERC-2942: EthPM URI Specification

Defines `ethpm://` URIs that name an EthPM package registry, a package, a specific release, or a single asset inside it in one string, so tools can install and share smart-contract packages easily.

What problem does it solve?

EthPM is a package-management system for smart contracts: packages (ABIs, bytecode, deployment addresses, sources) are described by a manifest (EIP-2678) and published to on-chain registries (ERC-1319). To install or point someone at a package, a user had to supply several separate facts: which chain, which registry contract, which package name, which version.

ERC-2942 packs all of that into a single URI, the same way https:// or git+ssh:// URLs identify resources elsewhere.

How it works

The general shape is:

scheme://registry_address[:chain_id][/package_name[@package_version[/json_pointer]]]
Part Required Meaning
scheme yes ethpm or erc1319 (future registry ERCs may add schemes)
registry_address yes an ENS name or a checksummed 0x address of the registry
chain_id no chain the registry lives on; defaults to 1 (mainnet)
package_name no name of the package
package_version no release version; URL-unsafe characters must be percent-escaped
json_pointer no an RFC 6901 JSON pointer to one asset inside the release manifest

Each optional part narrows the target: registry → package → release → asset. If the version is omitted and several releases exist, tools should not guess (semver is not enforced) and should ask the user to choose.

Sample code

Example URIs (addresses and names are placeholders):

ethpm://0x1234...AbCd                                   registry on mainnet
ethpm://0x1234...AbCd:5/owned                           package "owned" on chain 5
ethpm://packages.eth/[email protected]                          release via an ENS-named registry
ethpm://packages.eth:1/[email protected]/contractTypes/DSToken/abi   one asset in the release

A minimal parser in TypeScript:

const RE = /^(ethpm|erc1319):\/\/([^/:]+)(?::(\d+))?(?:\/([^@/]+)(?:@([^/]+)(\/.*)?)?)?$/;

function parseEthpmUri(uri: string) {
  const m = RE.exec(uri);
  if (!m) throw new Error("not an EthPM URI");
  const [, scheme, registry, chainId, pkg, version, pointer] = m;
  return {
    scheme,
    registry,
    chainId: chainId ? Number(chainId) : 1,   // default: mainnet
    pkg,
    version: version && decodeURIComponent(version),
    pointer,                                   // JSON pointer, e.g. "/contractTypes/X/abi"
  };
}

Things to know

  • Status is Stagnant. EthPM itself saw limited adoption, and support in the tools the spec lists (Brownie, Truffle, EthPM CLI) should be checked before relying on it.
  • Using an ENS name as the registry (EIP-137) is convenient but means trusting whoever controls the name: it can be repointed to a different registry. Use a checksummed address when integrity matters.
  • A URI that pins registry, package and version generally identifies an immutable release; leaving parts out makes it a moving target.

#ethpm #packages #uri #tooling #registry

Details

Authors
Nick Gheorghita (@njgheorghita), Piper Merriam (@pipermerriam), g. nicholas d'andrea (@gnidan), Benjamin Hauser (@iamdefinitelyahuman)
Status
Stagnant
Type
Standards Track / ERC
Created
2020-09-04
Requires

Machine-readable: Markdown · JSON