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
impl ContractRepository
pub fn new( api_provider: ApiClientProvider, configuration: TenderlyConfiguration, ) -> Result<Self, GeneralError>
Sourcepub async fn get(&self, address: &str) -> Result<Contract, GeneralError>
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.
Sourcepub async fn add(
&self,
address: &str,
contract_data: Option<&ContractData>,
) -> Result<Contract, GeneralError>
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.
Sourcepub async fn remove(&self, address: &str) -> Result<(), GeneralError>
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.
Sourcepub async fn update(
&self,
address: &str,
payload: &UpdateContractRequest,
) -> Result<Contract, GeneralError>
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 updatepayload- 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.
Sourcepub async fn get_all(&self) -> Result<Vec<Contract>, GeneralError>
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.
Sourcepub async fn get_by(
&self,
query_object: &GetByParams,
) -> Result<Vec<Contract>, GeneralError>
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.
Sourcepub async fn verify(
&self,
address: &str,
verification_request: &VerificationRequest,
) -> Result<Contract, GeneralError>
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 verifyverification_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.