diff --git a/src/toolchain/katana/interact.md b/src/toolchain/katana/interact.md index 1b73215f..86e8146d 100644 --- a/src/toolchain/katana/interact.md +++ b/src/toolchain/katana/interact.md @@ -5,30 +5,45 @@ curl https://get.starkli.sh | sh ## open a new terminal starkliup ``` + You can check your installation by running `starkli --version`,then you will get the starkli version. + ### install katana + ```console git clone https://github.com/dojoengine/dojo cd dojo cargo install --path ./crates/katana --locked --force ``` + You can check your installation by running `katana --version`,then you will get the katana version. + ### Deploy and interact with contracts + #### run katana node + ```console katana --accounts 3 --seed 0 --gas-price 250 ``` + After starting the node, the accounts you need will be automatically generated and deployed. We need to import the pre-deployed accounts into starkli for use. + #### Configure starkli account + 1. Configure the signer, execute the following command, and then enter the private key. This private key is the private key of the account generated by kanata. + ```console starkli signer keystore from-key ~/.starkli-wallets/deployer/account0_keystore.json ``` + 2. Configure account description and create a new json file + ```console touch ~/.starkli-wallets/deployer/account0_account.json ``` + 3. Copy the following content into the json file + ```console { "version": 1, @@ -44,13 +59,19 @@ touch ~/.starkli-wallets/deployer/account0_account.json } } ``` + Change `<>` and its contents to those provided by katana, including `public_key`, `class_hash`, and `address`.Among them, `class_hash` needs to be obtained with the following command. Please replace `` with address. + ```console starkli class-hash-at --rpc http://0.0.0.0:5050 ``` + In order to facilitate subsequent contract deployment and invocation, three accounts are deployed directly here. The process is the same.we will get 6 json files. + #### Contract Deployment + 1. Create a Vote project + ```console ## create a new project scarb new vote @@ -60,7 +81,9 @@ starknet = "2.1.0" [[target.starknet-contract]] casm = true ``` + Copy the vote contract to lib.cairo + ```console /// @dev Core Library Imports for the Traits outside the Starknet Contract use starknet::ContractAddress; @@ -238,27 +261,37 @@ mod Vote { } } ``` + 2. Compile contract + ```console scarb build ``` + 3. Declare contract + ```console starkli declare target/dev/test_Vote.sierra.json --compiler-version 2.1.0 --rpc http://0.0.0.0:5050 --account ~/.starkli-wallets/deployer/account0_account.json --keystore ~/.starkli-wallets/deployer/account0_keystore.json ``` + 4. Deploy contract + ```console ## starkli deploy --rpc http://0.0.0.0:5050 --account ~/.starkli-wallets/deployer/account0_account.json --keystore ~/.starkli-wallets/deployer/account0_keystore.json ## There are four hexadecimal numbers in total. The first one is the class_hash of the contract, and the next three are the vote account addresses, which are the three account addresses in the previous account configuration. ## Below is the command I ran,you need to change it to your address starkli deploy 0x043e965f6c644b15c0c46d5615c22cf26746edc2547f482ae5ab517d3dffdf37 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 0x5686a647a9cdd63ade617e0baf3b364856b813b508f03903eb58a7e622d5855 0x765149d6bc63271df7b0316537888b81aa021523f9516a05306f10fd36914da --rpc http://0.0.0.0:5050 --account ~/.starkli-wallets/deployer/account0_account.json --keystore ~/.starkli-wallets/deployer/account0_keystore.json ``` + 5. Call contract [only read state] + ```console ## The first parameter is the contract address, the second parameter is the function to be called, and the third parameter is the function parameter. Here I pass in a voting address. starkli call 0x050ffb64b3042bf91422dfa1453b3cdeaf4af7eca8562b499fc49017d41b85ec voter_can_vote 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 --rpc http://0.0.0.0:5050 ``` + 6. Invoke contract [can write state] + ```console ##The first parameter is the contract address, the second parameter is the function to be invoked, and the third parameter is the function parameter ##Voting Yes @@ -277,9 +310,12 @@ Unknown location (pc=0:677) Unknown location (pc=0:291) Unknown location (pc=0:314) ``` + 7. Query transaction + ```console ### starkli transaction --rpc http://0.0.0.0:5050 starkli transaction 0x0499bca29c88798ea70233c41d1d17621f49a2afb1f4ed902ca2eecf4a19e951 --rpc http://0.0.0.0:5050 ``` + All the above interaction processes can be seen on the katana client. Pay attention to the status changes of katana at each step.