Skip to content

Commit a91c53f

Browse files
ddoktorskiTHenry14DelevoXDG
authored
Update docs before 0.19.0 release (#1275)
* Update migration guide * Update docs * Add info about added versioned classes * Apply suggestions from code review Co-authored-by: Wojciech Szymczyk <wojciech.szymczyk@swmansion.com> * Improve clarity of Fees section in Using Existing Contract chapter * Fix hyperlinks to API documentation * Add transaction fee section * Apply suggestions from code review Co-authored-by: Wojciech Szymczyk <wojciech.szymczyk@swmansion.com> * Improve auto estimation warning * Update auto estimation warning message * Fix failing test * Apply suggestions from code review Co-authored-by: Maksim Zdobnikau <43750648+DelevoXDG@users.noreply.github.com> * Address review feedback * Update warning under `Fees` section Co-authored-by: Maksim Zdobnikau <43750648+DelevoXDG@users.noreply.github.com> * Add info about auto fee estimation under Fees --------- Co-authored-by: Wojciech Szymczyk <wojciech.szymczyk@swmansion.com> Co-authored-by: Maksim Zdobnikau <43750648+DelevoXDG@users.noreply.github.com>
1 parent 4c15080 commit a91c53f

14 files changed

+106
-71
lines changed

docs/account_creation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ Here is step by step example:
3232

3333
If you are experiencing transaction failures with ``FEE_TRANSFER_FAILURE``
3434
make sure that the address you are trying to deploy is prefunded with enough
35-
tokens, and verify that ``max_fee`` argument
36-
in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_transaction` is set
35+
tokens, and verify that ``max_fee`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v1`
36+
or ``l1_resource_bounds`` argument in :meth:`~starknet_py.net.account.account.Account.sign_deploy_account_v3` is set
3737
to a high enough value.

docs/development.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ Below is the command you can use to do this, designed for compatibility with the
2525

2626
.. code-block:: bash
2727
28-
STARKNET_VERSION="0.12.3" RPC_SPEC_VERSION="0.5.1" \
28+
STARKNET_VERSION="0.13.0" RPC_SPEC_VERSION="0.6.0" \
2929
cargo install \
3030
--locked \
3131
--git https://github.com/0xSpaceShard/starknet-devnet-rs.git \
32-
--rev 78527de
32+
--rev 1bd447d
3333
3434
If you choose to install `starknet-devnet-rs <https://github.com/0xSpaceShard/starknet-devnet-rs>`_ using a different method, please make sure to add the executable ``starknet-devnet`` to your ``PATH`` environment variable.
3535

docs/guide/account_and_client.rst

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,41 @@ Account and Client
44
Executing transactions
55
----------------------
66

7-
To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute` method from :ref:`Account` interface.
7+
To execute transactions on Starknet, use :meth:`~starknet_py.net.account.account.Account.execute_v1` or :meth:`~starknet_py.net.account.account.Account.execute_v3` methods from :ref:`Account` interface.
8+
These methods will send :class:`~starknet_py.net.models.InvokeV1` and :class:`~starknet_py.net.models.InvokeV3` transactions respectively. To read about differences between transaction versions please visit `transaction types <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions>`_ from the Starknet docs.
89

910
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_executing_transactions.py
1011
:language: python
1112
:dedent: 4
1213

14+
Transaction Fee
15+
---------------
16+
17+
All methods within the :ref:`Account` that involve on-chain modifications require either specifying a maximum transaction fee or using auto estimation.
18+
In the case of V1 and V2 transactions, the transaction fee, denoted in Wei, is configured by the ``max_fee`` parameter.
19+
For V3 transactions, however, the fee is expressed in Fri and is determined by the ``l1_resource_bounds`` parameter.
20+
To enable auto estimation, set the ``auto_estimate`` parameter to ``True``.
21+
22+
.. code-block:: python
23+
24+
resp = await account.execute_v1(calls=call, auto_estimate=True)
25+
26+
.. warning::
27+
28+
It is strongly discouraged to use automatic fee estimation in production code as it may lead to an unexpectedly high fee.
29+
30+
The returned estimated fee is multiplied by ``1.5`` for V1 and V2 transactions to mitigate fluctuations in price.
31+
For V3 transactions, ``max_amount`` and ``max_price_per_unit`` are scaled by ``1.1`` and ``1.5`` respectively.
32+
33+
34+
.. note::
35+
It is possible to configure the value by which the estimated fee is multiplied,
36+
by changing ``ESTIMATED_FEE_MULTIPLIER`` for V1 and V2 transactions in :class:`~starknet_py.net.account.account.Account`.
37+
The same applies to ``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.
38+
1339
Creating transactions without executing them
1440
--------------------------------------------
1541

16-
Alongside the simpler :meth:`~starknet_py.net.account.account.Account.execute`,
1742
Account also provides a way of creating signed transaction without sending them.
1843

1944
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_account_sign_without_execute.py
@@ -24,7 +49,7 @@ Multicall
2449
---------
2550

2651
There is a possibility to execute an Invoke transaction containing multiple calls.
27-
Simply pass a list of calls to :meth:`~starknet_py.net.account.account.Account.execute` method.
52+
Simply pass a list of calls to :meth:`~starknet_py.net.account.account.Account.execute_v1` or :meth:`~starknet_py.net.account.account.Account.execute_v3` methods.
2853
Note that the nonce will be bumped only by 1.
2954

3055
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_multicall.py
@@ -38,8 +63,6 @@ Note that the nonce will be bumped only by 1.
3863

3964
Do not pass arbitrarily large number of calls in one batch. Starknet rejects the transaction when it happens.
4065

41-
42-
4366
FullNodeClient usage
4467
--------------------
4568

docs/guide/deploying_contracts.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,21 @@ Deploying contracts
44
Declaring contracts
55
-------------------
66

7-
Since Cairo 0.10.0 Declare transactions can be signed and in the future, declaring without signing the transaction
8-
(and without paying the fee) will be impossible. That is why :ref:`Account` has
9-
:meth:`sign_declare_transaction()` method.
7+
A declare transaction can be issued in version 1, 2 or 3. Contracts written in Cairo 0 should be declared using version 1, while those written in Cairo 1 or higher should be declared with versions 2 or 3.
8+
To sign a declare transaction, you should utilize the :meth:`~starknet_py.net.account.account.Account.sign_declare_v1`, :meth:`~starknet_py.net.account.account.Account.sign_declare_v2` or :meth:`~starknet_py.net.account.account.Account.sign_declare_v3` method, respectively.
109

1110
Here's an example how to use it.
1211

1312
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_declaring_contracts.py
1413
:language: python
1514
:dedent: 4
1615

17-
.. note::
18-
19-
Signing Declare transactions is possible only with Accounts having `__validate__` entrypoint (with `supported_tx_version = 1`).
20-
21-
2216

2317
Simple declare and deploy
2418
-------------------------
2519

2620
The simplest way of declaring and deploying contracts on the Starknet is to use the :ref:`Contract` class.
27-
Under the hood, this flow sends :meth:`Declare` transaction and then sends :meth:`InvokeFunction`
21+
Under the hood, this flow first sends ``Declare`` transaction and then sends ``Invoke``
2822
through Universal Deployment Contract (UDC) to deploy a contract.
2923

3024
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_declare_and_deploy.py
@@ -34,7 +28,7 @@ through Universal Deployment Contract (UDC) to deploy a contract.
3428
Simple deploy
3529
-------------
3630

37-
If you already know the class hash of an already declared contract you want to deploy just use the :meth:`Contract.deploy_contract`.
31+
If you know the class hash of an already declared contract you want to deploy just use the :meth:`~starknet_py.contract.Contract.deploy_contract_v1` or :meth:`~starknet_py.contract.Contract.deploy_contract_v3`.
3832
It will deploy the contract using funds from your account. Deployment is handled by UDC.
3933

4034
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_simple_deploy.py
@@ -62,7 +56,6 @@ Deploying and using deployed contract in the same transaction
6256

6357
:ref:`Deployer` is designed to work with multicalls too. It allows to deploy a contract
6458
and call its methods in the same multicall, ensuring atomicity of all operations combined.
65-
Isn't it brilliant? Check out the code!
6659

6760
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_deploying_in_multicall.py
6861
:language: python
@@ -75,9 +68,7 @@ Cairo1 contracts
7568
Declaring Cairo1 contracts
7669
##########################
7770

78-
| Starknet 0.11 introduced the ability to declare contracts written in Cairo1!
79-
80-
To declare a new contract, Declare v2 or Declare v3 transaction has to be sent.
71+
To declare a contract in Cairo version 1 or higher, Declare V2 or Declare V3 transaction has to be sent.
8172
You can see the structure of these transactions `here <https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/transactions/#declare-transaction>`_.
8273

8374
The main differences in the structure of the transaction from its previous version are:

docs/guide/using_existing_contracts.rst

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,77 +37,81 @@ If you do not have ABI statically, but you know the interface of the contract on
3737
Fees
3838
----
3939

40-
starknet.py requires you to specify amount of Wei you
41-
are willing to pay either when making ``.invoke()`` transactions or when preparing
42-
function calls with ``.prepare()``.
40+
.. currentmodule:: starknet_py.contract
41+
42+
Starknet.py requires you to specify amount of Wei (for V1 transaction) or Fri (for V3 transaction) you
43+
are willing to pay when executing either :meth:`~ContractFunction.invoke_v1` or :meth:`~ContractFunction.invoke_v3` transactions.
44+
Alternatively, you can estimate fee automatically, as described in the :ref:`automatic-fee-estimation` section below.
4345

4446
.. code-block:: python
4547
46-
await contract.functions["put"].invoke(k, v, max_fee=5000)
48+
await contract.functions["put"].invoke_v1(k, v, max_fee=5000)
4749
48-
When max_fee is specified when preparing a call, you can invoke it without
49-
``max_fee``.
50+
The ``max_fee`` argument can be also defined in :meth:`~ContractFunction.prepare_invoke_v1`. Subsequently, the :meth:`~PreparedFunctionInvokeV1.invoke` method on a prepared call can be used either with ``max_fee`` omitted or with its value overridden.
51+
The same behavior applies to :meth:`~ContractFunction.prepare_invoke_v3` and ``l1_resource_bounds``.
5052

5153
.. code-block:: python
5254
53-
prepared_call = contract.function["put"].prepare(k, v, max_fee=5000)
55+
prepared_call = contract.function["put"].prepare_invoke_v1(k, v, max_fee=5000)
5456
await prepared_call.invoke()
57+
# or max_fee can be overridden
58+
await prepared_call.invoke(max_fee=10000)
5559
5660
.. warning::
5761

58-
If ``max_fee`` is not specified at any step it will default to ``None``,
59-
and will raise an exception when invoking a transaction.
62+
For V1 transactions if ``max_fee`` is not specified at any step it will default to ``None``,
63+
and will raise an exception when invoking a transaction, unless `auto_estimate` is specified and is set to `True`. The same applies to ``l1_resource_bounds`` and V3 transactions.
6064

61-
Please note you will need to have enough Wei in your Starknet account otherwise
65+
Please note you will need to have enough Wei (for V1 transaction) or Fri (for V3 transaction) in your Starknet account otherwise
6266
transaction will be rejected.
6367

6468
Fee estimation
6569
--------------
6670

6771
You can estimate required amount of fee that will need to be paid for transaction
68-
using :meth:`PreparedFunctionCall.estimate_fee() <starknet_py.contract.PreparedFunctionCall.estimate_fee>`
72+
using :meth:`PreparedFunctionInvoke.estimate_fee() <starknet_py.contract.PreparedFunctionInvoke.estimate_fee>`
6973

7074
.. code-block:: python
7175
72-
await contract.functions["put"].prepare(k, v, max_fee=5000).estimate_fee()
76+
await contract.functions["put"].prepare_invoke_v1(k, v).estimate_fee()
7377
78+
.. _automatic-fee-estimation:
7479

7580
Automatic fee estimation
7681
------------------------
7782

78-
For testing purposes it is possible to enable automatic fee estimation when making
79-
a transaction. starknet.py will then use ``estimate_fee()`` internally and use value
80-
returned by it multiplied by ``1.5`` as a ``max_fee``.
81-
82-
.. warning::
83-
84-
Do not use automatic fee estimation in production code! It may lead to
85-
very high fees paid as the amount returned by ``estimate_fee()`` may be arbitrarily large.
83+
For testing purposes it is possible to enable automatic fee estimation when making a transaction. Starknet.py will then call :meth:`~starknet_py.net.full_node_client.FullNodeClient.estimate_fee`
84+
internally and use the returned value, multiplied by ``1.5`` to mitigate fluctuations in price, as a ``max_fee`` for V1 transactions. For V3 transactions,
85+
``max_amount`` will be multiplied by ``1.1``, and ``max_price_per_unit`` by ``1.5``.
8686

8787
.. code-block:: python
8888
89-
await contract.functions["put"].invoke(k, v, auto_estimate=True)
89+
await contract.functions["put"].invoke_v1(k, v, auto_estimate=True)
90+
91+
.. warning::
9092

93+
It is strongly discouraged to use automatic fee estimation in production code as it may lead to unexpectedly high fee.
9194

9295
.. note::
93-
It is possible to configure the value by which the estimated fee is multiplied,
94-
by changing ``ESTIMATED_FEE_MULTIPLIER`` in :class:`~starknet_py.net.account.account.Account`.
96+
For V1 transactions it is possible to configure the value by which the estimated fee is multiplied,
97+
by changing ``ESTIMATED_FEE_MULTIPLIER`` in :class:`~starknet_py.net.account.account.Account`. The same applies to
98+
``ESTIMATED_AMOUNT_MULTIPLIER`` and ``ESTIMATED_UNIT_PRICE_MULTIPLIER`` for V3 transactions.
9599

96100
Account and Client interoperability
97101
-----------------------------------
98102

99103
.. currentmodule:: starknet_py.contract
100104

101-
:ref:`Contract` methods have been designed to be
102-
compatible with :ref:`Account` and :ref:`Client`.
105+
:ref:`Contract` methods have been designed to be compatible with :ref:`Account` and :ref:`Client`.
103106

104-
:ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare` can be used in Account methods to create Invoke transactions.
107+
:ref:`PreparedFunctionInvokeV1` and :ref:`PreparedFunctionInvokeV3` returned by :meth:`ContractFunction.prepare_invoke_v1` and :meth:`ContractFunction.prepare_invoke_v3` respectively can be used in Account methods to create Invoke transactions.
105108

106109
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_account_compatibility.py
107110
:language: python
108111
:dedent: 4
109112

110-
It can also be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`
113+
114+
Similarly, :ref:`PreparedFunctionCall` returned by :meth:`ContractFunction.prepare_call` can be used in :meth:`Client.call_contract() <starknet_py.net.client.Client.call_contract>`
111115

112116
.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_contract_client_compatibility.py
113117
:language: python

docs/migration_guide.rst

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,37 @@ Changes in the :class:`~starknet_py.net.account.account.Account`:
1616

1717
.. currentmodule:: starknet_py.net.account.account
1818

19-
- :meth:`~Account.execute_v3` has been added.
20-
- :meth:`~Account.sign_declare_v3`, :meth:`~Account.sign_deploy_account_v3` and :meth:`~Account.sign_invoke_v3` have been added.
21-
- :meth:`sign_declare_transaction`, :meth:`sign_declare_v2_transaction`, :meth:`sign_deploy_account_transaction` and :meth:`sign_invoke_transaction` have been renamed to :meth:`~Account.sign_declare_v1`, :meth:`~Account.sign_declare_v2`, :meth:`~Account.sign_deploy_account_v1` and :meth:`~Account.sign_invoke_v1` respectively.
19+
- :meth:`~Account.execute` has been renamed to :meth:`~Account.execute_v1`
20+
- :meth:`~Account.execute_v3` has been added
21+
- :meth:`~Account.deploy_account` has been renamed to :meth:`~Account.deploy_account_v1`
22+
- :meth:`~Account.deploy_account_v3` has been added
23+
- :meth:`~Account.sign_declare_v3`, :meth:`~Account.sign_deploy_account_v3` and :meth:`~Account.sign_invoke_v3` have been added
24+
- :meth:`sign_declare_transaction`, :meth:`sign_declare_v2_transaction`, :meth:`sign_deploy_account_transaction` and :meth:`sign_invoke_transaction` have been renamed to :meth:`~Account.sign_declare_v1`, :meth:`~Account.sign_declare_v2`, :meth:`~Account.sign_deploy_account_v1` and :meth:`~Account.sign_invoke_v1` respectively
2225

2326
All new functions with ``v3`` in their name operate similarly to their ``v1`` and ``v2`` counterparts.
24-
Unlike their ``v1`` counterparts, ``v3`` transaction fees are paid in Fri (10^-18 STRK). Therefore, ``max_fee`` parameter, which is typically set in Wei, is not applicable for ``v3`` functions. Instead, ``l1_resource_bounds`` parameter is utilized to limit the Fri amount used.
27+
Unlike their ``v1`` counterparts however, ``v3`` transaction fees are paid in Fri (10^-18 STRK). Therefore, ``max_fee`` parameter, which is typically set in Wei, is not applicable for ``v3`` functions. Instead, ``l1_resource_bounds`` parameter is utilized to limit the Fri amount used.
28+
The same applies to the new ``v3`` methods in the :class:`~starknet_py.contract.Contract` class.
2529

2630
Changes in the :class:`~starknet_py.net.full_node_client.FullNodeClient`:
2731

2832
.. currentmodule:: starknet_py.net.full_node_client
2933

30-
- :meth:`~FullNodeClient.estimate_fee` has a new parameter ``skip_validate``.
34+
- :meth:`~FullNodeClient.estimate_fee` has a new parameter ``skip_validate``
3135
- :meth:`~FullNodeClient.declare` accepts ``transaction`` argument of the type :class:`~starknet_py.net.models.transaction.DeclareV3`
3236
- :meth:`~FullNodeClient.send_transaction` accepts ``transaction`` argument of the type :class:`~starknet_py.net.models.transaction.InvokeV3`
3337
- :meth:`~FullNodeClient.deploy_account` accepts ``transaction`` argument of the type :class:`~starknet_py.net.models.transaction.DeployAccountV3`
3438

35-
.. warning::
36-
:class:`~starknet_py.contract.Contract` class does not support V3 transactions in the pre-release.
39+
Changes in the :class:`~starknet_py.contract.Contract`:
3740

41+
.. currentmodule:: starknet_py.contract
42+
43+
- :meth:`Contract.declare` has been replaced by :meth:`Contract.declare_v1`, :meth:`Contract.declare_v2` and :meth:`Contract.declare_v3`
44+
- :meth:`Contract.deploy_contract` has been replaced by :meth:`Contract.deploy_contract_v1` and :meth:`Contract.deploy_contract_v3`. Optional parameters ``unique`` and ``salt`` have been added to both methods
45+
- :meth:`ContractFunction.prepare` has been replaced by :meth:`ContractFunction.prepare_invoke_v1`, :meth:`ContractFunction.prepare_invoke_v3` and :meth:`ContractFunction.prepare_call`
46+
- :meth:`ContractFunction.invoke` has been replaced by :meth:`ContractFunction.invoke_v1` and :meth:`ContractFunction.invoke_v3`
47+
- :meth:`PreparedFunctionCall` has now only methods :meth:`PreparedFunctionCall.call` and :meth:`PreparedFunctionCall.call_raw`
48+
- :meth:`PreparedFunctionInvokeV1` and :meth:`PreparedFunctionInvokeV3` with methods ``invoke`` and ``estimate_fee`` have been added
49+
- :meth:`DeclareResult.deploy` has been replaced by :meth:`DeclareResult.deploy_v1` and :meth:`DeclareResult.deploy_v3`
3850

3951
0.19.0 Targeted versions
4052
------------------------
@@ -44,6 +56,7 @@ Changes in the :class:`~starknet_py.net.full_node_client.FullNodeClient`:
4456

4557
0.19.0 Breaking changes
4658
-----------------------
59+
Other breaking changes not mentioned above.
4760

4861
.. currentmodule:: starknet_py.net.client_models
4962

@@ -60,6 +73,9 @@ Changes in the :class:`~starknet_py.net.full_node_client.FullNodeClient`:
6073
11. :class:`ResourceLimits` class has been renamed to :class:`ResourceBounds`.
6174
12. :class:`~starknet_py.net.account.base_account.BaseAccount` and :class:`~starknet_py.net.account.account.Account` property ``supported_transaction_version`` has been removed.
6275
13. ``wait_for_accept`` parameter in :meth:`Client.wait_for_tx` and :meth:`SentTransaction.wait_for_acceptance` has been removed.
76+
14. :class:`InvokeTransaction` has been replaced by :class:`InvokeTransactionV0` and :class:`InvokeTransactionV1`.
77+
15. :class:`DeclareTransaction` has been replaced by :class:`DeclareTransactionV0`, :class:`DeclareTransactionV1` and :class:`DeclareTransactionV3`.
78+
16. :class:`DeployAccountTransaction` has been replaced by :class:`DeployAccountTransactionV1`.
6379

6480
0.19.0 Minor changes
6581
--------------------

docs/quickstart.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ It supports an account contract which proxies the calls to other contracts on St
3030

3131
Account can be created in two ways:
3232

33-
* By constructor (address, key_pair and net must be known).
34-
* By static method ``Account.deploy_account``
33+
* By constructor (It is required to provide an ``address`` and either ``key_pair`` or ``signer``).
34+
* By static methods ``Account.deploy_account_v1`` or ``Account.deploy_account_v3``
3535

3636
There are some examples how to do it:
3737

@@ -58,7 +58,7 @@ Using Contract
5858

5959
.. note::
6060

61-
To check if invoke succeeds use wait_for_acceptance on InvokeResult and get its status.
61+
To check if invoke succeeded use ``wait_for_acceptance`` on InvokeResult and get its status.
6262

6363
Although asynchronous API is recommended, you can also use Contract's synchronous API:
6464

starknet_py/tests/e2e/docs/account_creation/test_deploy_prefunded_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def test_deploy_prefunded_account(
5858
chain = chain_from_network(net=network, chain=StarknetChainId.GOERLI)
5959
# docs: start
6060

61-
# Use `Account.deploy_account_v1` static method to deploy an account
61+
# Use `Account.deploy_account_v1` or `Account.deploy_account_v3` static methods to deploy an account
6262
account_deployment_result = await Account.deploy_account_v1(
6363
address=address,
6464
class_hash=class_hash,

0 commit comments

Comments
 (0)