Skip to content

Commit

Permalink
docs: add docs for starknet-contract
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jul 29, 2024
1 parent 66ac385 commit 245c441
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions starknet-contract/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const SELECTOR_DEPLOYCONTRACT: Felt = Felt::from_raw([
18249998464715511309,
]);

/// A contract factory that acts as a blueprint for deploying Starknet smart contracts using the
/// Universal Deployer Contract.
#[derive(Debug)]
pub struct ContractFactory<A> {
class_hash: Felt,
Expand Down Expand Up @@ -62,10 +64,15 @@ pub struct DeploymentV3<'f, A> {
}

impl<A> ContractFactory<A> {
/// Constructs a new [`ContractFactory`] from a class hash and an account.
///
/// The [`ContractFactory`] created uses the default address for the Universal Deployer
/// Contract. To use a custom UDC deployment, use [`new_with_udc`](fn.new_with_udc) instead.
pub const fn new(class_hash: Felt, account: A) -> Self {
Self::new_with_udc(class_hash, account, UDC_ADDRESS)
}

/// Constructs a new [`ContractFactory`] with a custom Universal Deployer Contract address.
pub const fn new_with_udc(class_hash: Felt, account: A, udc_address: Felt) -> Self {
Self {
class_hash,
Expand All @@ -79,6 +86,8 @@ impl<A> ContractFactory<A>
where
A: Account,
{
/// Generates an instance of [`DeploymentV1`] for sending `INVOKE` v1 transactions for the
/// contract deployment. Pays transaction fees in `ETH`.
pub const fn deploy_v1(
&self,
constructor_calldata: Vec<Felt>,
Expand All @@ -96,6 +105,8 @@ where
}
}

/// Generates an instance of [`DeploymentV3`] for sending `INVOKE` v3 transactions for the
/// contract deployment. Pays transaction fees in `STRK`.
pub const fn deploy_v3(
&self,
constructor_calldata: Vec<Felt>,
Expand All @@ -115,6 +126,8 @@ where
}
}

/// Generates an instance of [`DeploymentV1`] for sending `INVOKE` v1 transactions for the
/// contract deployment. Pays transaction fees in `ETH`.
#[deprecated = "use version specific variants (`deploy_v1` & `deploy_v3`) instead"]
pub const fn deploy(
&self,
Expand Down
10 changes: 10 additions & 0 deletions starknet-contract/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
//! Library for deploying and interacting with Starknet contracts.
//!
//! Currently, this crate only provides a single type [`ContractFactory`] for deploying contracts
//! using the Universal Deployer Contract.
//!
//! In the future, features like ABI-based contract binding generation will be added to allow type-
//! safe interaction with Starknet smart contracts.
#![deny(missing_docs)]

mod factory;
pub use factory::ContractFactory;

0 comments on commit 245c441

Please sign in to comment.