software-mansion / starknet.py Goto Github PK
View Code? Open in Web Editor NEWโจ ๐ Python SDK for Starknet.
Home Page: https://starknetpy.rtfd.io/
License: MIT License
โจ ๐ Python SDK for Starknet.
Home Page: https://starknetpy.rtfd.io/
License: MIT License
Is your feature request related to a problem? Please describe.
As of 0.8.2.1 starknet allows for passing "latest"
as blockNumber .
Since 0.9 or later, starknet will require explicitly providing blockNumber parameter in the following methods
These methods in starknet.py must be modified to use a default block_number="latest"
parameter to continue to work in future versions.
In addition to the new declare method: #158 we will have to change contract's deploy method.
Describe the solution you'd like
Contract.deploy should take class_hash instead of compilation_source and compiled_contract.
We should change starknet_compile
and all functions using it to allow passing search paths.
Currently we only search for files within active directory. It is very difficult to manage scripts from external resources, like git submodule.
When I interact with a smart-contract via calling a mutable method on the live Testnet (goerli alpha), I get an Unknown location error.
Python 3.7.9
I can call mutable methods on contracts from goerli
I get the following error:
ERROR: (ContractLogicError) Error at pc=0:32:Got an exception while executing a hint.Cairo traceback (most recent call last):Unknown location (pc=0:497)Unknown location (pc=0:456)Unknown location (pc=0:513)Error in the called contract (0x7394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10):Error at pc=0:6:Got an exception while executing a hint.Cairo traceback (most recent call last):Unknown location (pc=0:795)Unknown location (pc=0:772)Unknown location (pc=0:1232)Traceback (most recent call last): File "<hint0>", line 3, in <module>AssertionError: assert_not_zero failed: 0 = 0.').
I am using the test token contract deployed to 0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10
When I deploy an ERC20 to my local starknet-devnet
, I can call mutable methods and things work just fine.
We need to grab the ABI from the implementation contract.
from starknet_py.contract import Contract
from starknet_py.net import AccountClient
from starknet_py.net import KeyPair
# This account comes from ArgentX and is a proxy contract.
# The error I get is that it cannot find the __execute__ ABI.
# The __execute__ method needs to be grabbed from the implementation contract.
account_address = 2976162931320574283751166485501184860501729793478009661243729394508001134570
# Create the account client (note: my pkey is omitted for obvious reasons)
key_pair = KeyPair(
private_key=******,
public_key=888158711641686699726990655481927574337047407568
)
account_client = AccountClient(
account_address,
key_pair,
'https://alpha4.starknet.io',
chain=1536727068981429685321,
)
my_other_account = 3037460148268451690947737348211282823053350676597561718645135357343745417603
# Init the ETH token contract from its address
token_address = "0x07394cbe418daa16e42b87ba67372d4ab4a5df0b05c6e554d158458ce245bc10"
token_contract = Contract.from_address_sync(token_address, account_client)
receipt = token_contract.functions["transfer"].invoke_sync(my_other_account, 100, max_fee=100)
print(receipt) # Does not get here
Trying to interact with the ETH contract (which is a proxy)
Also, trying to use my Argent X account (which is a proxy)
In general, I have trouble with proxy contracts
Fetch ABI from proxy first by calling implementation()
Is your feature request related to a problem? Please describe.
A way to check an account's balance in the token that fees are required to be paid in.
Describe the solution you'd like
account_client.get_balance()
that makes a call to the ETH ERC20 contract to get the amount of tokens that account has.
Describe alternatives you've considered
A tokens lists type manager is probably bigger picture
Additional context
I might be missing something obvious.
I am going to have to implement this myself because I need this functionality but I am wondering if it would make better sense here.
3.7.12
Tests should be linted
They are not
__init__.py
to tests directoryIs your feature request related to a problem? Please describe.
Since this PR starknet-devnet added support for transactions with positive fee. Our e2e tests should be changed to use non 0 max_fee value.
Describe the solution you'd like
Use predeployed accounts from devnet to send fees with transactions
Describe alternatives you've considered
None
Additional context
Using fees in every tests that requires them will enable us to more easily use our tests on testnet.
Any
Tests should run in parallel
They do not run at all
Add env
configuration to poe test_e2e_parallel
as it is missing devnet port.
Local web page not created when running poe test. 404 error generated in
3.9.12
estimate_fee_sync
should successfully complete
It returns the following error:
{"code": "StarknetErrorCode.TRANSACTION_FAILED", "message": "Error at pc=0:392:\nUnknown value for memory cell at address 12:0.\nCairo traceback (most recent call last):\nUnknown location (pc=0:534)\nUnknown location (pc=0:468)"}
(nonce,) = keeper_contract.functions["get_nonce"].call_sync()
task_address_felt = int(task["address"], 16)
args, signature = get_account_message_args_sig(keeper_address, registry, "executeTask", [task_address_felt], nonce, key)
unsigned_invocation = keeper_contract.functions["execute"].prepare(*args)
# This is where the error occurs
estimation = unsigned_invocation.estimate_fee_sync()
# This normally runs perfectly fine if I don't do gas estimation for all these transactions that are failing with `estimate_fee`
invocation = unsigned_invocation.invoke_sync(signature=signature, max_fee=0)
FYI - I'm using an older version of an account contract to issue transactions but I'm assuming that this should not impact estimate fee as the other starknet.py
apis are working fine?
I've been using the excellent starknet.py
library to power Yagi Keepers (http://www.yagi.fi/automation).
I'm trying to upgrade keepers now to use fees on testnet before they are officially mandated.
When installing in a fresh environment, I try to follow the README but I get the following error:
>>> from starknet_py.net.client import Client
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jules/PycharmProjects/starknet.py/starknet_py/net/__init__.py", line 1, in <module>
from .client import Client
File "/Users/jules/PycharmProjects/starknet.py/starknet_py/net/client.py", line 16, in <module>
from starknet_py.net.models.address import BlockIdentifier
File "/Users/jules/PycharmProjects/starknet.py/starknet_py/net/models/__init__.py", line 8, in <module>
from .transaction import (
File "/Users/jules/PycharmProjects/starknet.py/starknet_py/net/models/transaction.py", line 9, in <module>
from starkware.starknet.services.api.gateway.transaction_hash import (
ModuleNotFoundError: No module named 'starkware.starknet.services.api.gateway.transaction_hash'
This is because this module was moved in this PR: starkware-libs/cairo-lang@ed6cf8d
Python 3.7.9
I can import the Client
class.
Errors about a module not being found.
Change the import path (see linked PR)
I am trying to evaluate this library for usage in a plugin for our development framework for starknet.
We should cover all the code usage examples from our docs, to know when we're starting to provide a usage example which is outdated/broken.
Is your feature request related to a problem? Please describe.
There is a better way of creating the account client
Describe the solution you'd like
Change this:
acc_client = await AccountClient.create_account(
net=run_devnet, chain=StarknetChainId.TESTNET
)
to this:
acc_client = await DevnetClientFactory(run_devnet).make_devnet_client()
Is your feature request related to a problem? Please describe.
Currently, to run e2e tests on testnet, parameters have to be manually changed in multiple places. Ideally there should be some kind of switch that allows easily changing between devnet and testnet.
Describe the solution you'd like
Custom pytest parameter to toggle between tests
Describe alternatives you've considered
Some simple code interface for selecting net address
Additional context
n/a
Is your feature request related to a problem? Please describe.
I am unable to make useful assertions on rejection reasons because the exception that gets raised in a generic exception that does not reveal any of the information.
Describe the solution you'd like
In client.wait_for_tx()
, raise a custom error TransactionRejected(result["message"])
that includes that failure reason from the result
.
Describe alternatives you've considered
Implementing a custom wait_for_tx()
.
Additional context
I was failing to sign a transaction correctly but the error message was not telling me that. I had to set a breakpoint in the lib to find out the details of the failure.
Is your feature request related to a problem? Please describe.
Currently when deployment of the contract fails after deploy transaction was made (e.g. when constructor calldata provided was incorrect and assertion error was thrown), Contract.deploy
still returns a DeploymentResult that hast be verified by the user, for example using Client.wait_for_tx()
. I think it would be useful for Contract.deploy
to be able to fail when deployment is unsuccessful.
Describe the solution you'd like
Provide a parameter like wait_for_deploy
so Contract.deploy checks for successful deployment and raises an exception if it's not.
Is your feature request related to a problem? Please describe.
I am trying to install this package in an environment using web3.py==5.27.0
but this package is pinned to web3.py==5.3.0
.
Describe the solution you'd like
Upgrade the web3.py
dependency to include 5.27.0
in its supported range as well addressing any migrations related to this upgrade.
Describe alternatives you've considered
Not using this library directly or forking it? I don't know, the starknet APIs currently seem tricky. This is an excellent resources nonetheless!
account_client.deploy should let the user deploy new contracts
The proxy contract will work with a class rather than a contract, that is implementation_address would change to class_hash.
There is an implementation of ArgentProxyCheck and OpenZeppelinProxyCheck in our project, so we should check how they will manage this change.
Is your feature request related to a problem? Please describe.
With current setup it is impossible to run tests either through cli or IDE integrations without setting DEVNET_PORT env var before. This variable is no longer used so this setup is unnecessary.
Also it may lead to bugs in tests as not passing run_devnet
to DevnetClientFactory
, it will try to use a default parameter using devnet_port, and the connection will fail (since there'd be no devnet instance at this port).
Describe the solution you'd like
Remove DEVNET_PORT and related default value entirely
Is your feature request related to a problem? Please describe.
Support changes from starknet 0.8.2 (e.g. endpoints with new parameters, "latest" block)
Is your feature request related to a problem? Please describe.
Method of calculating a transaction hash has now changed, update tests to reflect those changes
In StarkNet Alpha 0.9.0 there will be a new type of transaction.
Declare transaction will put contract's definition to StarkNet.
Describe the solution you'd like
New declare method in Contract class.
Is your feature request related to a problem? Please describe.
Currently checks do not run in external PRs
Describe the solution you'd like
Checks should run in PRs made from forks
Is your feature request related to a problem? Please describe.
Arguments for get_transaction_receipt
no longer include tx_id
field
Is your feature request related to a problem? Please describe.
The problem comes from PR #131 where we have functionality that should be tested on testnet, but as correctly pointed out by @Arcticae these tests probably shouldn't be run on every commit as they introduce significant overhead.
Describe the solution you'd like
Some change in how these tests are run should be introduced.
Describe alternatives you've considered
Here are some ideas:
Is your feature request related to a problem? Please describe.
I think that running docs tests everytime you use poe test_e2e
is unfavourable behavior. I think we should consider changing.
Describe the solution you'd like
More control over running docs tests
Describe alternatives you've considered
Similarly to how you can now disable tests that run on testnet.
Additional context
I think it unnecessarily increases run time of the tests, when realistically docs tests should only be run on CI/locally before finishing a change.
Describe the solution you'd like
Add support for max_fee when creating transactions.
Especially AccountClient.add_transaction should either
and it should use this fee when creating MultiCall
Hey thanks for developing starknet.py
, awesome lib we are starting to use at https://yagi.fi! Friendly (possible) bug report.
I'm trying to deploy an account contract using deploy_sync
but it hangs rather than returning the pending tx (which is what invoke_sync
does).
3.8
Should return pending tx.
Hangs.
Match invoke_sync
behavior with deploy_sync
.
source_code = Path("contracts/Account.cairo").read_text("utf-8")
result = Contract.deploy_sync(
client=Client("testnet"),
compilation_source=source_code,
constructor_args={
"_public_key": public_key
}
)
Not able to deploy an account contract using starknet.py
.
Estimate fee in the account contract should prepare all data like in add_transaction method (e.g. signature) and use estimate_fee from Client with this data.
Create estimate_fee method in AccountClient which will check the fee in the context of AccountClient
##Current behavior
Now you have to provide a signature to estimate_fee which is not correct
Is your feature request related to a problem? Please describe.
Add support for version
and max_fee
arguments now required by calculate_transaction_hash_common()
Is your feature request related to a problem? Please describe.
If documentation build ends with a failure, checks for whole commit should fail.
Currently if there are errors while generating docs (e.g. missing pages), we often end up unaware of these errors.
Describe the solution you'd like
Checks should fail
Is your feature request related to a problem? Please describe.
It is not a problem, but I like the transaction management and private key establishment that happens in this method however it is limited to the OZ contract. It would be nice to be able to allow the user to specify any contract to use here (and have it default to the OZ one).
Describe the solution you'd like
Allow the user to specify a separate contract to use in AccountClient.create_account()
Describe alternatives you've considered
Implement outside of lib.
Additional context
Add any other context or screenshots about the feature request here.
Is your feature request related to a problem? Please describe.
Currently each e2e test is run in the single devnet instance. This may allow for unpredictable side effects of previous tests to influence results of the rest.
Describe the solution you'd like
Isolate tests from eachother
Describe alternatives you've considered
Additional context
Test are already quite slow, so we may need to consider some optimisation or ignore this issue entirely if it's not possible to run multiple devnets efficiently.
pyproject.toml in line 25 should be:
test_e2e.shell = "starknet-devnet --host localhost --port 5000 ; DEVNET_PID=$! && sleep 1 && coverage run -m pytest starknet/tests/e2e; kill $DEVNET_PID"
When an error occurs on a contract, the error message includes the class name and is difficult to parse as a string.
Python 3.7.9
The error message only contains str or JSON like dict instead of class
The error message has a stringified class
Convert class to JSON dict first? (fast solution)
Or grab the important fields from the class and compose a nicer error message (ideal solutioin)
Create a contract that you know will error (I am using starknet-devnet)
Call method that causes error
See error message.
It looks something like this:
Transaction was rejected with following starknet error: TransactionFailureReason(code='TRANSACTION_FAILED', error_message='Error message: Already initialized\nError at pc=0:118:\nAn ASSERT_EQ instruction failed: 1 != 0.\nCairo traceback (most recent call last):\nUnknown location (pc=0:132)').
Notice the part that says TransactionFailureReason
, that is like a class.. I really just want the code and the error_message
from it but I have to parse the whole thing as a string.
Makes parsing and forming custom errors challenging.
Use more primitive data types.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.