software-mansion / starknet.py

✨ 🐍 Python SDK for Starknet.
https://starknetpy.rtfd.io/
MIT License
260 stars 82 forks source link

Where to get private_key class_hash salt? #753

Closed JackGod001 closed 1 year ago

JackGod001 commented 1 year ago

Feature Request

I want to generate an account, but the official is running starknet new_account I can't get private_key class_hash salt, and I can't find it in the documentation, can you tell me how they generated it? Is there any way to build?

starknet new_account                                                               

Account address: 0x05bcf64c57fed542750bfd2e1b2335193a8f1ff546cf8d783f9bef55a361fdfc
Public key: 0x01f1038bf688cde87a480096c3d7eb68bd64577cf8141248f89845349bea9a9c
Move the appropriate amount of funds to the account, and then deploy the account
by invoking the 'starknet deploy_account' command.

NOTE: This is a modified version of the OpenZeppelin account contract. The signature is computed
differently.
key_pair = KeyPair.from_private_key(private_key)
# Compute an address
address = compute_address(
    salt=salt,
    class_hash=class_hash,  # class_hash of the Account declared on the StarkNet
    constructor_calldata=[key_pair.public_key],
    deployer_address=0,
)
drknzz commented 1 year ago

Hey, you can see the details of the account you created through the CLI, by inspecting the file with accounts:

cat ~/.starknet_accounts/starknet_open_zeppelin_accounts.json

It should look something like this:

{
    "alpha-goerli": {
        "__default__": {
            "private_key": "...",
            "public_key": "...",
            "salt": "...",
            "address": "...",
            "deployed": false
        },
        "second_account": {
            ...
        },
    }
}

The class hash of the OpenZeppelin account used, when creating through CLI is:

0x06f500f527355dfdb8093c7fe46e6f73c96a867392b49fa4157a757538928539
JackGod001 commented 1 year ago

Hey, you can see the details of the account you created through the CLI, by inspecting the file with accounts:嘿,您可以通过检查带有帐户的文件来查看您通过 CLI 创建的帐户的详细信息:

cat ~/.starknet_accounts/starknet_open_zeppelin_accounts.json

It should look something like this:它应该看起来像这样:

{
    "alpha-goerli": {
        "__default__": {
            "private_key": "...",
            "public_key": "...",
            "salt": "...",
            "address": "...",
            "deployed": false
        },
        "second_account": {
            ...
        },
    }
}

The class hash of the OpenZeppelin account used, when creating through CLI is:通过 CLI 创建时使用的 OpenZeppelin 帐户的类哈希是:

0x06f500f527355dfdb8093c7fe46e6f73c96a867392b49fa4157a757538928539

I can't find the starknet_open_zeppelin_accounts.json file, but would like to provide some examples of using OpenZeppelin account in a python non-cli way. I can find print in the source code, and I can print out salt, private_key by modifying the source code, but how is the mnemonic phrase calculated? I want to use it to import into argentx

drknzz commented 1 year ago

So the starknet_open_zeppelin_accounts.json in ~/.starknet_accounts/ directory is created after the first use of

starknet new_account

from the CLI. It gives you all the details of the account.

If you would like to know the internals, of how things are calculated, when creating a new account, you could check out the implementation from cairo-lang.

JackGod001 commented 1 year ago

So the starknet_open_zeppelin_accounts.json in ~/.starknet_accounts/ directory is created after the first use starknet_open_zeppelin_accounts.json ~/.starknet_accounts/ first use starknet_open_zeppelin_accounts.json ~/.starknet_accounts/ 首次使用 of

starknet new_account

from the CLI. It gives you all the details of the account.

If you would like to know the internals, of how things are calculated, when creating a new account, you could check out the implementation from cairo-lang 查看实现 cairo-lang 查看实现 cairo-lang .

Yes I have found the code for the implementation, I would like to know how to calculate private_key using mnemonics

war-in commented 1 year ago

Hey, I don't think CLI is using mnemonics at all. There should be some library to do so in python (there is but I don't know if it is valid or not)

JackGod001 commented 1 year ago

I tried to use the eth account mnemonic phrase generated by web3 can be imported into the argent-x plugin, but the private key of the eth account cannot be used in starknet_py, I want to generate an account with mnemonic, private key, public key in python that can be used in argent-x plugin. But I haven't found a solution yet

war-in commented 1 year ago

I think you can ask at argent-x channel on the StarkNet discord server. They should know how to calculate private key from the mnemonics :)