ContractRepository

Struct ContractRepository 

Source
pub struct ContractRepository { /* private fields */ }
Expand description

Contract service for managing contracts in your Tenderly project

Provides functionality to add, update, remove, and query contracts. Supports contract verification, metadata management, and filtering by tags or display names.

§Example

use tenderly_rs::{
    services::ContractData,
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;

// Add a contract
let contract = tenderly
    .contracts
    .add(
        "0x6b175474e89094c44da98b954eedeac495271d0f",
        Some(&ContractData {
            display_name: Some("DAI Token".to_string()),
        }),
    )
    .await?;

// Get a contract
let contract = tenderly
    .contracts
    .get("0x6b175474e89094c44da98b954eedeac495271d0f")
    .await?;

Implementations§

Source§

impl ContractRepository

Source

pub fn new( api_provider: ApiClientProvider, configuration: TenderlyConfiguration, ) -> Result<Self, GeneralError>

Source

pub async fn get(&self, address: &str) -> Result<Contract, GeneralError>

Get a contract by address

Retrieves contract information from your Tenderly project for the configured network.

§Arguments
  • address - Contract address (hex string with or without 0x prefix)
§Returns

Returns Contract if found, or GeneralError::NotFound if the contract is not in your project.

§Example
use tenderly_rs::{
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

let contract = contracts
    .get("0x6b175474e89094c44da98b954eedeac495271d0f")
    .await?;
println!("Contract: {}", contract.address);
§Errors

Returns GeneralError::NotFound if the contract is not found, or GeneralError::ApiError if the API request fails.

Source

pub async fn add( &self, address: &str, contract_data: Option<&ContractData>, ) -> Result<Contract, GeneralError>

Add a contract to the project

Adds a contract address to your Tenderly project for monitoring and tracking. Optionally includes metadata like display name for easier identification.

§Arguments
  • address - Contract address (hex string with or without 0x prefix)
  • contract_data - Optional metadata including display name
§Returns

Returns the added Contract object.

§Example
use tenderly_rs::{
    services::ContractData,
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

let contract = contracts
    .add(
        "0x6b175474e89094c44da98b954eedeac495271d0f",
        Some(&ContractData {
            display_name: Some("DAI Token".to_string()),
        }),
    )
    .await?;
§Errors

Returns GeneralError::ApiError if the API request fails.

Source

pub async fn remove(&self, address: &str) -> Result<(), GeneralError>

Remove a contract from the project

Removes a contract address from your Tenderly project. This does not delete contract verification data, only removes it from your project’s tracked contracts.

§Arguments
  • address - Contract address to remove
§Example
use tenderly_rs::{
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

contracts
    .remove("0x6b175474e89094c44da98b954eedeac495271d0f")
    .await?;
§Errors

Returns GeneralError::ApiError if the API request fails.

Source

pub async fn update( &self, address: &str, payload: &UpdateContractRequest, ) -> Result<Contract, GeneralError>

Update a contract’s metadata

Updates contract metadata including display name and tags. You can update display name, add tags, or both in a single call.

§Arguments
  • address - Contract address to update
  • payload - Update request containing display name and/or tags to append
§Returns

Returns the updated Contract object.

§Example
use tenderly_rs::{
    services::contracts::types::UpdateContractRequest,
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

let update_request = UpdateContractRequest {
    display_name: Some("Updated Name".to_string()),
    append_tags: Some(vec!["defi".to_string(), "token".to_string()]),
};

let updated = contracts.update("0x...", &update_request).await?;
§Errors

Returns GeneralError::ApiError if the API request fails.

Source

pub async fn get_all(&self) -> Result<Vec<Contract>, GeneralError>

Get all contracts in the project

Retrieves all contracts currently tracked in your Tenderly project for the configured network.

§Returns

Returns a vector of Contract objects.

§Example
use tenderly_rs::{
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

let all_contracts: Vec<_> = contracts.get_all().await?;
println!("Found {} contracts", all_contracts.len());
§Errors

Returns GeneralError::ApiError if the API request fails.

Source

pub async fn get_by( &self, query_object: &GetByParams, ) -> Result<Vec<Contract>, GeneralError>

Get contracts by query parameters

Retrieves contracts filtered by display names and/or tags. Useful for finding specific contracts in large projects.

§Arguments
  • query_object - Query parameters containing optional display names and tags filters
§Returns

Returns a vector of Contract objects matching the query.

§Example
use tenderly_rs::{
    services::contracts::types::GetByParams,
    Network,
    Tenderly,
    TenderlyConfiguration,
};

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Mainnet,
))?;
let contracts = &tenderly.contracts;

let query = GetByParams {
    display_names: Some(vec!["DAI Token".to_string()]),
    tags: Some(vec!["defi".to_string()]),
};

let filtered = contracts.get_by(&query).await?;
§Errors

Returns GeneralError::ApiError if the API request fails.

Source

pub async fn verify( &self, address: &str, verification_request: &VerificationRequest, ) -> Result<Contract, GeneralError>

Verify a contract’s source code

Verifies a contract by submitting its source code and compiler settings. After verification, the contract’s source code becomes viewable on Tenderly, and you can interact with verified functions.

§Arguments
  • address - Contract address to verify
  • verification_request - Verification request containing source code, compiler config, and verification mode
§Returns

Returns the verified Contract object.

§Example
use tenderly_rs::{Network, Tenderly, TenderlyConfiguration};
use tenderly_rs::services::contracts::types::*;
use std::collections::HashMap;

let tenderly = Tenderly::new(TenderlyConfiguration::new(
    "account".to_string(),
    "project".to_string(),
    "key".to_string(),
    Network::Sepolia,
))?;
let contracts = &tenderly.contracts;

let mut sources = HashMap::new();
sources.insert("Counter.sol".to_string(), SourceContent {
    content: "pragma solidity ^0.8.0; contract Counter { }".to_string(),
});

let solc_config = SolcConfig {
    version: "v0.8.18".to_string(),
    sources,
    settings: serde_json::json!({"optimizer": {"enabled": false}}),
};

let request = VerificationRequest {
    contract_to_verify: "Counter.sol:Counter".to_string(),
    solc: solc_config,
    config: VerificationConfig {
        mode: VerificationMode::Public,
    },
};

let verified = contracts.verify("0x...", &request).await?;
§Errors

Returns GeneralError::Compilation if source code compilation fails, GeneralError::BytecodeMismatch if bytecode doesn’t match, GeneralError::ApiError if the API request fails, or GeneralError::InvalidArguments if contract name format is invalid.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more