Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/guide/account_and_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ Note that the nonce will be bumped only by 1.
FullNodeClient usage
--------------------

Use a :ref:`FullNodeClient` to interact with services providing `Starknet rpc interface <https://github.com/starkware-libs/starknet-specs/blob/606c21e06be92ea1543fd0134b7f98df622c2fbf/api/starknet_api_openrpc.json>`_
like `Pathfinder Full Node <https://github.com/eqlabs/pathfinder>`_ or starknet-devnet. starknet.py provides uniform interface for
both gateway and full node client - usage is exactly the same as gateway client minus some optional
parameters.

Use a :ref:`FullNodeClient` to interact with services providing `Starknet RPC interface <https://github.com/starkware-libs/starknet-specs/blob/606c21e06be92ea1543fd0134b7f98df622c2fbf/api/starknet_api_openrpc.json>`_
like `Pathfinder <https://github.com/eqlabs/pathfinder>`_,
`Papyrus <https://github.com/starkware-libs/papyrus>`_, `Juno <https://github.com/NethermindEth/juno>`_
or `starknet-devnet <https://github.com/0xSpaceShard/starknet-devnet>`_.
Using own full node allows for querying Starknet with better performance.
Since gateway will be deprecated at some point in the future, having ``FullNodeClient`` with interface uniform with that of ``GatewayClient``
will allow for simple migration for starknet.py users.

Since GatewayClient is deprecated and will be removed at some point in the future, having ``FullNodeClient``
with interface uniform with that of ``GatewayClient`` will allow for simple migration for starknet.py users.

.. codesnippet:: ../../starknet_py/tests/e2e/docs/guide/test_full_node_client.py
:language: python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ async def test_deploy_prefunded_account(
account_with_validate_deploy_class_hash: int,
network: str,
fee_contract: Contract,
gateway_client: Client,
full_node_client: Client,
):
# pylint: disable=import-outside-toplevel, too-many-locals
# docs: start
from starknet_py.hash.address import compute_address
from starknet_py.net.account.account import Account
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models import StarknetChainId
from starknet_py.net.networks import TESTNET
from starknet_py.net.signer.stark_curve_signer import KeyPair

# First, make sure to generate private key and salt
Expand Down Expand Up @@ -50,11 +49,11 @@ async def test_deploy_prefunded_account(
# docs: start

# Define the client to be used to interact with Starknet
client = GatewayClient(net=TESTNET)
client = FullNodeClient(node_url="your.node.url")
chain = StarknetChainId.TESTNET
# docs: end

client = gateway_client
client = full_node_client
chain = chain_from_network(net=network, chain=StarknetChainId.TESTNET)
# docs: start

Expand Down
14 changes: 7 additions & 7 deletions starknet_py/tests/e2e/docs/code_examples/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

def test_init():
# docs-start: init
account = Account(
address=0x123,
client=FullNodeClient(node_url="your.node.url"),
key_pair=KeyPair(12, 34),
chain=StarknetChainId.TESTNET,
)
# or (not recommended, soon GatewayClient will be removed)
account = Account(
address=0x123,
client=GatewayClient(net=TESTNET),
Expand All @@ -26,13 +33,6 @@ def test_init():
chain_id=StarknetChainId.TESTNET,
),
)
# or
account = Account(
address=0x123,
client=FullNodeClient(node_url="your.node.url"),
key_pair=KeyPair(12, 34),
chain=StarknetChainId.TESTNET,
)
# docs-end: init


Expand Down
6 changes: 3 additions & 3 deletions starknet_py/tests/e2e/docs/code_examples/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def test_init():
],
provider=Account(
address=0x321,
client=GatewayClient(TESTNET),
client=FullNodeClient(node_url="your.node.url"),
key_pair=KeyPair(12, 34),
chain=StarknetChainId.TESTNET,
),
)
# or
# or (not recommended, soon GatewayClient will be removed)
contract = Contract(
address=0x123,
abi=[
Expand All @@ -42,7 +42,7 @@ def test_init():
],
provider=Account(
address=0x321,
client=FullNodeClient(TESTNET),
client=GatewayClient(TESTNET),
key_pair=KeyPair(12, 34),
chain=StarknetChainId.TESTNET,
),
Expand Down
17 changes: 5 additions & 12 deletions starknet_py/tests/e2e/docs/guide/test_cairo1_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

from starknet_py.net.client_models import CasmClass
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.udc_deployer.deployer import _get_random_salt
from starknet_py.tests.e2e.fixtures.constants import CONTRACTS_COMPILED_V1_DIR, MAX_FEE
from starknet_py.tests.e2e.fixtures.misc import read_contract
Expand All @@ -13,23 +12,17 @@
async def test_cairo1_contract(
account,
sierra_minimal_compiled_contract_and_class_hash,
another_sierra_minimal_compiled_contract_and_class_hash,
gateway_client,
):
# pylint: disable=import-outside-toplevel, too-many-locals
# pylint: disable=too-many-locals
# pylint: disable=import-outside-toplevel
(
compiled_contract,
compiled_class_hash,
) = (
sierra_minimal_compiled_contract_and_class_hash
if isinstance(account.client, GatewayClient)
else another_sierra_minimal_compiled_contract_and_class_hash
)
) = sierra_minimal_compiled_contract_and_class_hash

contract_compiled_casm = read_contract(
"minimal_contract_compiled.casm"
if isinstance(account.client, GatewayClient)
else "another_minimal_contract_compiled.casm",
"minimal_contract_compiled.casm",
directory=CONTRACTS_COMPILED_V1_DIR,
)

Expand Down Expand Up @@ -94,6 +87,6 @@ async def test_cairo1_contract(
assert contract_deployment.address != 0

compiled_class = await gateway_client.get_compiled_class_by_class_hash(
sierra_class_hash
class_hash=sierra_class_hash
)
assert isinstance(compiled_class, CasmClass)
4 changes: 2 additions & 2 deletions starknet_py/tests/e2e/docs/guide/test_custom_nonce.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@


@pytest.mark.asyncio
async def test_custom_nonce(gateway_client):
async def test_custom_nonce(full_node_client):
# pylint: disable=import-outside-toplevel
address = 0x1
client = gateway_client
client = full_node_client
private_key = 0x1

# docs: start
Expand Down
4 changes: 2 additions & 2 deletions starknet_py/tests/e2e/docs/guide/test_custom_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def test_custom_signer():

# docs: start
from starknet_py.net.account.account import Account
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models import StarknetChainId, Transaction
from starknet_py.net.signer import BaseSigner
from starknet_py.utils.typed_data import TypedData
Expand All @@ -30,7 +30,7 @@ def sign_message(

# Create an Account instance with the signer you've implemented
custom_signer = CustomSigner()
client = GatewayClient("testnet")
client = FullNodeClient(node_url="your.node.url")
account = Account(
client=client,
address=0x1111,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async def test_sign_offchain_message(account):

# docs: start
from starknet_py.net.account.account import Account
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models import StarknetChainId
from starknet_py.net.signer.stark_curve_signer import KeyPair
from starknet_py.utils.typed_data import TypedData
Expand Down Expand Up @@ -52,7 +52,7 @@ async def test_sign_offchain_message(account):
# docs: start

# Create an Account instance
client = GatewayClient("testnet")
client = FullNodeClient(node_url="your.node.url")
account = Account(
client=client,
address="0x1111",
Expand Down
14 changes: 4 additions & 10 deletions starknet_py/tests/e2e/docs/quickstart/test_creating_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@


@pytest.mark.asyncio
async def test_creating_account(network):
async def test_creating_account():
# pylint: disable=import-outside-toplevel, unused-variable
# docs: start
from starknet_py.net.account.account import Account
from starknet_py.net.gateway_client import GatewayClient
from starknet_py.net.full_node_client import FullNodeClient
from starknet_py.net.models.chains import StarknetChainId
from starknet_py.net.signer.stark_curve_signer import KeyPair

testnet = "testnet"
# docs: end
testnet = network
# docs: start

# Creates an instance of account which is already deployed (testnet)

# Creates an instance of account which is already deployed
# Account using transaction version=1 (has __validate__ function)
client = GatewayClient(net=testnet)
client = FullNodeClient(node_url="your.node.url")
account = Account(
client=client,
address="0x4321",
Expand Down