Skip to content

Commit bbfcd16

Browse files
committed
Merge branch 'development'
2 parents 11cc665 + 62f1089 commit bbfcd16

File tree

186 files changed

+2240
-2435
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+2240
-2435
lines changed

.github/workflows/checks.yml

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Checks
33
env:
44
CAIRO_LANG_VERSION: "0.13.1"
55
DEVNET_VERSION: "0.1.2"
6+
DEVNET_SHA: 7e7dbb5
7+
LEDGER_APP_SHA: dd58c5c
68

79
on:
810
push:
@@ -97,7 +99,7 @@ jobs:
9799
# ====================== CONTRACTS v2 ====================== #
98100
- name: Cache contracts v2
99101
id: cache-contracts_v2
100-
uses: actions/cache@v3
102+
uses: actions/cache@v4
101103
with:
102104
path: starknet_py/tests/e2e/mock/contracts_v2/target
103105
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts_v2') }}
@@ -111,7 +113,7 @@ jobs:
111113

112114
- name: Cache contracts v1
113115
id: cache-contracts_v1
114-
uses: actions/cache@v3
116+
uses: actions/cache@v4
115117
with:
116118
path: starknet_py/tests/e2e/mock/contracts_v1/target
117119
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts_v1') }}
@@ -120,29 +122,8 @@ jobs:
120122
if: steps.cache-contracts_v1.outputs.cache-hit != 'true'
121123
run: |
122124
poetry run poe compile_contracts v1
123-
124-
# ====================== CONTRACTS v0 ====================== #
125125
126-
- name: Cache contracts v0
127-
id: cache-contracts
128-
uses: actions/cache@v3
129-
with:
130-
path: starknet_py/tests/e2e/mock/contracts_compiled
131-
key: ${{ runner.os }}-contracts-${{ hashFiles('starknet_py/tests/e2e/mock/contracts', 'poetry.lock') }}-${{ env.CAIRO_LANG_VERSION }}
132-
133-
- name: Install deprecated cairo compiler
134-
if: steps.cache-contracts.outputs.cache-hit != 'true'
135-
run: |
136-
pip install --upgrade setuptools
137-
pip install sympy==1.11.1
138-
pip install cairo-lang==${{ env.CAIRO_LANG_VERSION }}
139-
140-
- name: Compile contracts v0
141-
if: steps.cache-contracts.outputs.cache-hit != 'true'
142-
run: |
143-
poetry run poe compile_contracts v0
144-
145-
- name: Upload contracts v0
126+
- name: Upload contracts artifacts
146127
uses: actions/upload-artifact@v3
147128
with:
148129
name: contract-artifacts
@@ -159,7 +140,7 @@ jobs:
159140
strategy:
160141
fail-fast: false
161142
matrix:
162-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
143+
python-version: [ "3.8", "3.12" ]
163144
env:
164145
LEDGER_PROXY_ADDRESS: 127.0.0.1
165146
LEDGER_PROXY_PORT: 9999
@@ -217,6 +198,7 @@ jobs:
217198
options: --rm -v ${{ github.workspace }}:/apps
218199
run: |
219200
cd /apps/app-starknet
201+
git checkout ${{ env.LEDGER_APP_SHA }}
220202
cargo clean
221203
cargo ledger build nanox
222204
@@ -307,6 +289,11 @@ jobs:
307289
run: |
308290
poetry install
309291
292+
# ====================== SETUP DEVNET ====================== #
293+
294+
- name: Install devnet
295+
run: ./starknet_py/tests/install_devnet.sh
296+
310297
# ====================== RUN TESTS ====================== #
311298

312299
- name: Check circular imports
@@ -336,7 +323,7 @@ jobs:
336323
strategy:
337324
fail-fast: false
338325
matrix:
339-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
326+
python-version: [ "3.8", "3.12" ]
340327
env:
341328
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
342329
steps:
@@ -358,11 +345,19 @@ jobs:
358345

359346
# ====================== SETUP DEVNET ====================== #
360347

348+
- name: Cache devnet build
349+
id: windows-devnet-cache
350+
uses: actions/cache@v4
351+
with:
352+
path: ${{ github.workspace }}\starknet_py\tests\e2e\devnet\bin
353+
key: ${{ runner.os }}-devnet-${{ env.DEVNET_SHA }}
354+
361355
- name: Install devnet
356+
if: steps.windows-devnet-cache.outputs.cache-hit != 'true'
362357
run: |
363-
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
364-
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 7e7dbb5 --root $DEVNET_INSTALL_DIR
365-
358+
$DEVNET_INSTALL_DIR = "${{ github.workspace }}\starknet_py\tests\e2e\devnet"
359+
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev ${{ env.DEVNET_SHA }} --root $DEVNET_INSTALL_DIR
360+
shell: pwsh
366361
# ====================== SETUP PYTHON ====================== #
367362

368363
- name: Install poetry
@@ -410,7 +405,7 @@ jobs:
410405
strategy:
411406
fail-fast: false
412407
matrix:
413-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
408+
python-version: [ "3.8", "3.12" ]
414409
steps:
415410
- uses: actions/checkout@v4
416411

@@ -474,7 +469,7 @@ jobs:
474469
strategy:
475470
fail-fast: false
476471
matrix:
477-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
472+
python-version: [ "3.8", "3.12" ]
478473
steps:
479474
- uses: actions/checkout@v4
480475
- uses: dtolnay/rust-toolchain@dc6353516c68da0f06325f42ad880f76a5e77ec9
@@ -512,10 +507,19 @@ jobs:
512507
513508
# ====================== SETUP DEVNET ====================== #
514509

510+
- name: Cache devnet build
511+
id: windows-devnet-cache
512+
uses: actions/cache@v4
513+
with:
514+
path: ${{ github.workspace }}\starknet_py\tests\e2e\devnet\bin
515+
key: ${{ runner.os }}-devnet-${{ env.DEVNET_SHA }}
516+
515517
- name: Install devnet
518+
if: steps.windows-devnet-cache.outputs.cache-hit != 'true'
516519
run: |
517-
$DEVNET_INSTALL_DIR = "$(git rev-parse --show-toplevel)/starknet_py/tests/e2e/devnet"
518-
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev 7e7dbb5 --root $DEVNET_INSTALL_DIR
520+
$DEVNET_INSTALL_DIR = "${{ github.workspace }}\starknet_py\tests\e2e\devnet"
521+
cargo install --git https://github.com/0xSpaceShard/starknet-devnet-rs.git --locked --rev ${{ env.DEVNET_SHA }} --root $DEVNET_INSTALL_DIR
522+
shell: pwsh
519523

520524
# ====================== RUN TESTS ====================== #
521525

.github/workflows/package.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
name: Build wheels
2-
on: workflow_dispatch
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
38

49
jobs:
510
build_sdist:

README.md

Lines changed: 166 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,186 @@ Installation varies between operating systems.
2929

3030
[See our documentation on complete instructions](https://starknetpy.rtfd.io/en/latest/installation.html)
3131

32-
## ▶️ Example usage
3332

34-
### Asynchronous API
33+
## 💨 Quickstart
34+
### Using FullNodeClient
35+
A [Client](https://starknetpy.readthedocs.io/en/latest/api/client.html#client) is a facade for interacting with Starknet.
36+
[FullNodeClient](https://starknetpy.readthedocs.io/en/latest/api/full_node_client.html#module-starknet_py.net.full_node_client) is a client which interacts with a Starknet full nodes like [Pathfinder](https://github.com/eqlabs/pathfinder), [Papyrus](https://github.com/starkware-libs/papyrus) or [Juno](https://github.com/NethermindEth/juno).
37+
It supports read and write operations, like querying the blockchain state or adding new transactions.
3538

36-
This is the recommended way of using the SDK.
3739

3840
```python
39-
from starknet_py.contract import Contract
4041
from starknet_py.net.full_node_client import FullNodeClient
4142

42-
contract = await Contract.from_address(
43-
address="0x06689f1bf69af5b8e94e5ab9778c885b37c593d1156234eb423967621f596e73",
44-
client=FullNodeClient(node_url="https://your.node.url"),
43+
node_url = "https://your.node.url"
44+
client = FullNodeClient(node_url=node_url)
45+
46+
call_result = await client.get_block(block_number=1)
47+
```
48+
The default interface is asynchronous. Although it is the recommended way of using starknet.py, you can also use a synchronous version. It might be helpful to play with Starknet directly in python interpreter.
49+
50+
```python
51+
node_url = "https://your.node.url"
52+
client = FullNodeClient(node_url=node_url)
53+
call_result = client.get_block_sync(block_number=1)
54+
```
55+
You can check out all of the FullNodeClient’s methods here: [FullNodeClient](https://starknetpy.readthedocs.io/en/latest/api/full_node_client.html#module-starknet_py.net.full_node_client).
56+
57+
### Creating Account
58+
[Account](https://starknetpy.readthedocs.io/en/latest/api/account.html#starknet_py.net.account.account.Account) is the default implementation of [BaseAccount](https://starknetpy.readthedocs.io/en/latest/api/account.html#starknet_py.net.account.base_account.BaseAccount) interface.
59+
It supports an account contract which proxies the calls to other contracts on Starknet.
60+
61+
Account can be created in two ways:
62+
- By constructor (It is required to provide an `address` and either `key_pair` or `signer`).
63+
- By static methods `Account.deploy_account_v1` or `Account.deploy_account_v3`
64+
65+
Additionally, you can use the [sncast](https://foundry-rs.github.io/starknet-foundry/starknet/index.html) tool to create an account,
66+
which will automatically be saved to a file.
67+
There are some examples how to do it:
68+
```python
69+
from starknet_py.net.account.account import Account
70+
from starknet_py.net.full_node_client import FullNodeClient
71+
from starknet_py.net.models.chains import StarknetChainId
72+
from starknet_py.net.signer.stark_curve_signer import KeyPair
73+
from starknet_py.net.signer.stark_curve_signer import StarkCurveSigner
74+
75+
# Creates an instance of account which is already deployed
76+
# Account using transaction version=1 (has __validate__ function)
77+
client = FullNodeClient(node_url="https://your.node.url")
78+
account = Account(
79+
client=client,
80+
address="0x4321",
81+
key_pair=KeyPair(private_key=654, public_key=321),
82+
chain=StarknetChainId.SEPOLIA,
83+
)
84+
85+
# There is another way of creating key_pair
86+
key_pair = KeyPair.from_private_key(key=123)
87+
# or
88+
key_pair = KeyPair.from_private_key(key="0x123")
89+
90+
# Instead of providing key_pair it is possible to specify a signer
91+
signer = StarkCurveSigner("0x1234", key_pair, StarknetChainId.SEPOLIA)
92+
93+
account = Account(
94+
client=client, address="0x1234", signer=signer, chain=StarknetChainId.SEPOLIA
95+
)
96+
```
97+
98+
### Using Account
99+
Example usage:
100+
101+
```python
102+
from starknet_py.contract import Contract
103+
from starknet_py.net.client_models import ResourceBounds
104+
l1_resource_bounds = ResourceBounds(
105+
max_amount=int(1e5), max_price_per_unit=int(1e13)
106+
)
107+
# Declare and deploy an example contract which implements a simple k-v store.
108+
# Contract.declare_v3 takes string containing a compiled contract (sierra) and
109+
# a class hash (casm_class_hash) or string containing a compiled contract (casm)
110+
declare_result = await Contract.declare_v3(
111+
account,
112+
compiled_contract=compiled_contract,
113+
compiled_class_hash=class_hash,
114+
l1_resource_bounds=l1_resource_bounds,
115+
)
116+
117+
await declare_result.wait_for_acceptance()
118+
deploy_result = await declare_result.deploy_v3(
119+
l1_resource_bounds=l1_resource_bounds,
45120
)
46-
(value,) = await contract.functions["get_balance"].call()
121+
# Wait until deployment transaction is accepted
122+
await deploy_result.wait_for_acceptance()
123+
124+
# Get deployed contract
125+
map_contract = deploy_result.deployed_contract
126+
k, v = 13, 4324
127+
# Adds a transaction to mutate the state of k-v store. The call goes through account proxy, because we've used
128+
# Account to create the contract object
129+
await (
130+
await map_contract.functions["put"].invoke_v3(
131+
k,
132+
v,
133+
l1_resource_bounds=ResourceBounds(
134+
max_amount=int(1e5), max_price_per_unit=int(1e13)
135+
),
136+
)
137+
).wait_for_acceptance()
138+
139+
# Retrieves the value, which is equal to 4324 in this case
140+
(resp,) = await map_contract.functions["get"].call(k)
141+
142+
# There is a possibility of invoking the multicall
143+
144+
# Creates a list of prepared function calls
145+
calls = [
146+
map_contract.functions["put"].prepare_invoke_v3(key=10, value=20),
147+
map_contract.functions["put"].prepare_invoke_v3(key=30, value=40),
148+
]
149+
150+
# Executes only one transaction with prepared calls
151+
transaction_response = await account.execute_v3(
152+
calls=calls,
153+
l1_resource_bounds=l1_resource_bounds,
154+
)
155+
await account.client.wait_for_tx(transaction_response.transaction_hash)
47156
```
48157

49-
### Synchronous API
158+
### Using Contract
159+
[Contract](https://starknetpy.readthedocs.io/en/latest/api/contract.html#starknet_py.contract.Contract) makes interacting with contracts deployed on Starknet much easier:
160+
```python
161+
from starknet_py.contract import Contract
162+
163+
contract_address = (
164+
"0x01336fa7c870a7403aced14dda865b75f29113230ed84e3a661f7af70fe83e7b"
165+
)
166+
key = 1234
167+
168+
# Create contract from contract's address - Contract will download contract's ABI to know its interface.
169+
contract = await Contract.from_address(address=contract_address, provider=account)
170+
171+
# If the ABI is known, create the contract directly (this is the preferred way).
172+
contract = Contract(
173+
address=contract_address,
174+
abi=abi,
175+
provider=account,
176+
cairo_version=1,
177+
)
50178

51-
You can access synchronous world with `_sync` postfix.
179+
# All exposed functions are available at contract.functions.
180+
# Here we invoke a function, creating a new transaction.
181+
invocation = await contract.functions["put"].invoke_v1(key, 7, max_fee=int(1e16))
182+
183+
# Invocation returns InvokeResult object. It exposes a helper for waiting until transaction is accepted.
184+
await invocation.wait_for_acceptance()
185+
186+
# Calling contract's function doesn't create a new transaction, you get the function's result.
187+
(saved,) = await contract.functions["get"].call(key)
188+
# saved = 7 now
189+
```
190+
191+
To check if invoke succeeded use `wait_for_acceptance` on InvokeResult and get its status.
192+
193+
Although asynchronous API is recommended, you can also use Contract’s synchronous API:
52194

53195
```python
54196
from starknet_py.contract import Contract
55-
from starknet_py.net.full_node_client import FullNodeClient
56197

57-
contract = Contract.from_address_sync(
58-
address="0x06689f1bf69af5b8e94e5ab9778c885b37c593d1156234eb423967621f596e73",
59-
client=FullNodeClient(node_url="https://your.node.url"),
198+
contract_address = (
199+
"0x01336fa7c870a7403aced14dda865b75f29113230ed84e3a661f7af70fe83e7b"
60200
)
61-
(value,) = contract.functions["get_balance"].call_sync()
201+
202+
key = 1234
203+
contract = Contract.from_address_sync(address=contract_address, provider=account)
204+
205+
invocation = contract.functions["put"].invoke_v1_sync(key, 7, max_fee=int(1e16))
206+
invocation.wait_for_acceptance_sync()
207+
208+
(saved,) = contract.functions["get"].call_sync(key) # 7
62209
```
63210

64-
For more examples click [here](https://starknetpy.rtfd.io/en/latest/quickstart.html).
211+
Contract automatically serializes values to Cairo calldata. This includes adding array lengths automatically.
212+
See more info in [Serialization](https://starknetpy.readthedocs.io/en/latest/guide/serialization.html#serialization).
213+
214+
Quickstart in docs - click [here](https://starknetpy.rtfd.io/en/latest/quickstart.html).

docs/account_creation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and then creating the transaction which will charge the fee from the address.
1616
Deploying an account with DeployAccount transaction requires the following:
1717

1818
- class_hash of the account contract
19-
- generating a private key and deployment salt
19+
- private key and deployment salt
2020
- computing an address based on the account's secrets
2121
- prefunding an address with the fee tokens (e.g. using the token bridge)
2222
- creating and signing a DeployAccount transaction with generated secrets

docs/api/models.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ Module containing base models and functions to operate on them.
1919
.. autoclass:: DeployAccountV3
2020
:exclude-members: __init__, __new__
2121

22-
.. autoclass:: DeclareV1
23-
:exclude-members: __init__, __new__
24-
2522
.. autoclass:: DeclareV2
2623
:exclude-members: __init__, __new__
2724

0 commit comments

Comments
 (0)