# Counter Contract Cheetsheet (Copied from Maciej: https://hackmd.io/@N6RypFCeTaCW_p1Hfqw5uw/r1jL9NJ3O) ## Use Counter Contract - cheatsheet #### 0. Generate account keys (if you have not already) ``` mkdir ../keys/integration.cspr.live/ casper-client keygen ../keys/integration.cspr.live/ ``` and fund the keys (ask CasperLabs team for test tokens). #### 1. Get the account status from the global state #### 1.1. Check account status – get the account address hash ``` casper-client account-address --public-key ../keys/integration.cspr.live/public_key_hex #### My public key: ac26250eba20b2337c4b93235654eaa503df4b665f0894aac26452cb409465d9 ``` #### 1.2. Check account status – get the state root hash You can retrieve an IP of one of the validator nodes from: https://integration.cspr.live/tools/peers ``` casper-client get-state-root-hash --node-address http://3.140.179.157:7777/rpc ``` #### 1.3. Get this account's status from the global state ``` casper-client query-state \ --node-address http://3.140.179.157:7777/rpc \ --state-root-hash <STATE_ROOT_HASH> \ --key account-hash-ac26250eba20b2337c4b93235654eaa503df4b665f0894aac26452cb409465d9 ``` #### 2. Compile the contracts and run the tests ``` make prepare make test ``` #### 3. Deploy the counter-define.wasm contract to the chain using 25 CSPR ``` casper-client put-deploy \ --node-address http://3.140.179.157:7777/rpc \ --chain-name integration-test \ --secret-key ../keys/integration.cspr.live/secret_key.pem \ --payment-amount 25000000000 \ --session-path ./target/wasm32-unknown-unknown/release/counter-define.wasm ``` #### 4. Check the status of the deploy #### 4.1. Option 1 – Use the CLI to ping the node directly ``` casper-client get-deploy --node-address http://3.140.179.157:7777/rpc <DEPLOY_HASH> ``` #### 4.2. Option 2 – Use the integration test block explorer https://integration.cspr.live/ (you must wait for the gossip to happen) #### 5. Check the account status on the network again #### 5.1. Check account status – get the state root hash ``` casper-client get-state-root-hash --node-address http://3.140.179.157:7777/rpc ``` #### 5.2. Get the account status from the global state to see the count value ``` casper-client query-state \ --node-address http://3.140.179.157:7777/rpc \ --state-root-hash ################################################################### \ --key account-hash-ac26250eba20b2337c4b93235654eaa503df4b665f0894aac26452cb409465d9 \ -q "counter/count" ``` #### 6. Invoke the counter_inc entry-point ``` casper-client put-deploy \ --node-address http://3.140.179.157:7777/rpc \ --chain-name integration-test \ --secret-key ../keys/integration.cspr.live/secret_key.pem \ --payment-amount 100000000 \ --session-name "counter" \ --session-entry-point "counter_inc" ``` #### 7. Check the account status on the network again #### 7.1. Check account status – Check the status of the deploy #### Option 1 – Use the CLI to ping the node directly ``` casper-client get-deploy --node-address http://3.140.179.157:7777/rpc <DEPLOY_HASH> ``` #### Option 2 – Use the integration test block explorer https://integration.cspr.live/ (must wait for the gossip) #### 7.2. Check account status – get the state root hash ``` casper-client get-state-root-hash --node-address http://3.140.179.157:7777/rpc ``` #### 7.3. Get the account status from the global state to see the count value ``` casper-client query-state \ --node-address http://3.140.179.157:7777/rpc \ --state-root-hash <STATE_ROOT_HASH> \ --key account-hash-ac26250eba20b2337c4b93235654eaa503df4b665f0894aac26452cb409465d9 \ -q "counter/count" ``` #### 8. Deploy the counter-call.wasm to increment the counter again ``` casper-client put-deploy \ --node-address http://[NODE_IP_ADDRESS]:7777 \ --chain-name integration-test \ --secret-key ../keys/integration.cspr.live/secret_key.pem \ --payment-amount 25000000000 \ --session-path ./counter/target/wasm32-unknown-unknown/release/counter-call.wasm ``` #### 9. Check the account status on the network again #### 9.1. Check account status – Check the status of the deploy #### Option 1 – Use the CLI to ping the node directly ``` casper-client get-deploy --node-address http://3.140.179.157:7777/rpc <DEPLOY_HASH> ``` #### Option 2 – Use the integration test block explorer https://integration.cspr.live/ (must wait for the gossip) #### 9.2. Check account status – get the state root hash ``` casper-client get-state-root-hash --node-address http://3.140.179.157:7777/rpc ``` #### 9.3. Get the account status from the global state to see the count value ``` casper-client query-state \ --node-address http://3.140.179.157:7777/rpc \ --state-root-hash ################################################################### \ --key account-hash-ac26250eba20b2337c4b93235654eaa503df4b665f0894aac26452cb409465d9 \ -q "counter/count" ```