Skip to main content

Crate sourcify

Crate sourcify 

Source
Expand description

§sourcify

A lightweight read-only wrapper for Sourcify, including the Sourcify v2 API and Sourcify 4byte signature API.

§Supported APIs

§Limitations

The crate is intentionally small: use Sourcify::v2 to retrieve verified contract data, source files, ABI, and metadata by chain ID and address, and use Sourcify::four_byte to resolve function selectors or event topics.

§Contract Source Lookup

use sourcify::{v2, Sourcify};

#[tokio::main]
async fn main() -> sourcify::Result<()> {
    let client = Sourcify::new();
    let contract = client
        .v2()
        .get_contract_with_fields(
            1,
            "0xdAC17F958D2ee523a2206206994597C13D831ec7",
            &[v2::field::SOURCES, v2::field::ABI, v2::field::METADATA],
        )
        .await?;

    if let Some(contract) = contract {
        println!("verified on chain {}", contract.chain_id);
    }

    Ok(())
}

§4byte Lookup

use sourcify::Sourcify;

#[tokio::main]
async fn main() -> sourcify::Result<()> {
    let client = Sourcify::new();
    let signatures = client.four_byte().lookup_function("0xa9059cbb").await?;

    for signature in signatures {
        println!("{}", signature.name);
    }

    Ok(())
}

Re-exports§

pub use error::Error;
pub use error::Result;

Modules§

error
Error and result types returned by this crate.
four_byte
Read-only Sourcify 4byte signature API client. See Client for the main entry point.
v2
Read-only Sourcify v2 API client. See Client for the main entry point.

Structs§

Sourcify
Shared entry point for the Sourcify v2 and 4byte clients.