Skip to content

Commit 7d8395f

Browse files
authored
docs: add docs for starknet-contract (#641)
1 parent 66ac385 commit 7d8395f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

starknet-contract/src/factory.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const SELECTOR_DEPLOYCONTRACT: Felt = Felt::from_raw([
2020
18249998464715511309,
2121
]);
2222

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

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

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

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

129+
/// Generates an instance of [`DeploymentV1`] for sending `INVOKE` v1 transactions for the
130+
/// contract deployment. Pays transaction fees in `ETH`.
118131
#[deprecated = "use version specific variants (`deploy_v1` & `deploy_v3`) instead"]
119132
pub const fn deploy(
120133
&self,
@@ -127,20 +140,25 @@ where
127140
}
128141

129142
impl<'f, A> DeploymentV1<'f, A> {
143+
/// Returns a new [`DeploymentV1`] with the `nonce`.
130144
pub fn nonce(self, nonce: Felt) -> Self {
131145
Self {
132146
nonce: Some(nonce),
133147
..self
134148
}
135149
}
136150

151+
/// Returns a new [`DeploymentV1`] with the `max_fee`.
137152
pub fn max_fee(self, max_fee: Felt) -> Self {
138153
Self {
139154
max_fee: Some(max_fee),
140155
..self
141156
}
142157
}
143158

159+
/// Returns a new [`DeploymentV1`] with the fee estimate multiplier. The multiplier is used
160+
/// when transaction fee is not manually specified and must be fetched from a
161+
/// [`Provider`](starknet_providers::Provider) instead.
144162
pub fn fee_estimate_multiplier(self, fee_estimate_multiplier: f64) -> Self {
145163
Self {
146164
fee_estimate_multiplier,
@@ -150,34 +168,43 @@ impl<'f, A> DeploymentV1<'f, A> {
150168
}
151169

152170
impl<'f, A> DeploymentV3<'f, A> {
171+
/// Returns a new [`DeploymentV3`] with the `nonce`.
153172
pub fn nonce(self, nonce: Felt) -> Self {
154173
Self {
155174
nonce: Some(nonce),
156175
..self
157176
}
158177
}
159178

179+
/// Returns a new [`DeploymentV3`] with the `gas`.
160180
pub fn gas(self, gas: u64) -> Self {
161181
Self {
162182
gas: Some(gas),
163183
..self
164184
}
165185
}
166186

187+
/// Returns a new [`DeploymentV3`] with the `gas_price`.
167188
pub fn gas_price(self, gas_price: u128) -> Self {
168189
Self {
169190
gas_price: Some(gas_price),
170191
..self
171192
}
172193
}
173194

195+
/// Returns a new [`DeploymentV3`] with the gas amount estimate multiplier. The multiplier is
196+
/// used when the gas amount is not manually specified and must be fetched from a
197+
/// [`Provider`](starknet_providers::Provider) instead.
174198
pub fn gas_estimate_multiplier(self, gas_estimate_multiplier: f64) -> Self {
175199
Self {
176200
gas_estimate_multiplier,
177201
..self
178202
}
179203
}
180204

205+
/// Returns a new [`DeploymentV3`] with the gas price estimate multiplier. The multiplier is
206+
/// used when the gas price is not manually specified and must be fetched from a
207+
/// [`Provider`](starknet_providers::Provider) instead.
181208
pub fn gas_price_estimate_multiplier(self, gas_price_estimate_multiplier: f64) -> Self {
182209
Self {
183210
gas_price_estimate_multiplier,
@@ -234,11 +261,14 @@ impl<'f, A> DeploymentV1<'f, A>
234261
where
235262
A: ConnectedAccount + Sync,
236263
{
264+
/// Estimates transaction fees from a [`Provider`](starknet_providers::Provider).
237265
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
238266
let execution: ExecutionV1<'_, A> = self.into();
239267
execution.estimate_fee().await
240268
}
241269

270+
/// Simulates the transaction from a [`Provider`](starknet_providers::Provider). Transaction
271+
/// validation and fee transfer can be skipped.
242272
pub async fn simulate(
243273
&self,
244274
skip_validate: bool,
@@ -248,6 +278,7 @@ where
248278
execution.simulate(skip_validate, skip_fee_charge).await
249279
}
250280

281+
/// Signs and broadcasts the transaction to the network.
251282
pub async fn send(&self) -> Result<InvokeTransactionResult, AccountError<A::SignError>> {
252283
let execution: ExecutionV1<'_, A> = self.into();
253284
execution.send().await
@@ -258,11 +289,14 @@ impl<'f, A> DeploymentV3<'f, A>
258289
where
259290
A: ConnectedAccount + Sync,
260291
{
292+
/// Estimates transaction fees from a [`Provider`](starknet_providers::Provider).
261293
pub async fn estimate_fee(&self) -> Result<FeeEstimate, AccountError<A::SignError>> {
262294
let execution: ExecutionV3<'_, A> = self.into();
263295
execution.estimate_fee().await
264296
}
265297

298+
/// Simulates the transaction from a [`Provider`](starknet_providers::Provider). Transaction
299+
/// validation and fee transfer can be skipped.
266300
pub async fn simulate(
267301
&self,
268302
skip_validate: bool,
@@ -272,6 +306,7 @@ where
272306
execution.simulate(skip_validate, skip_fee_charge).await
273307
}
274308

309+
/// Signs and broadcasts the transaction to the network.
275310
pub async fn send(&self) -> Result<InvokeTransactionResult, AccountError<A::SignError>> {
276311
let execution: ExecutionV3<'_, A> = self.into();
277312
execution.send().await

starknet-contract/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
//! Library for deploying and interacting with Starknet contracts.
2+
//!
3+
//! Currently, this crate only provides a single type [`ContractFactory`] for deploying contracts
4+
//! using the Universal Deployer Contract.
5+
//!
6+
//! In the future, features like ABI-based contract binding generation will be added to allow type-
7+
//! safe interaction with Starknet smart contracts.
8+
9+
#![deny(missing_docs)]
10+
111
mod factory;
2-
pub use factory::ContractFactory;
12+
pub use factory::{ContractFactory, DeploymentV1, DeploymentV3};

0 commit comments

Comments
 (0)