Smart Contract Interactions using clio
Overview
In the article you’ll learn how to execute actions on a contract with the clio
tool. It guides you through inserting and updating records, checking updates, and testing out behavior on unauthorized change attempt.
Prerequisites
- Installation and Development Environment Setup
- Company contract tutorial
- Two new accounts
jack
andnick
clio create account sysio jack $PUBLIC_KEY -p sysio@active
clio create account sysio nick $PUBLIC_KEY -p sysio@active
Steps
Step 1: Insert a record
First, let’s have Jack insert or update his own record.
clio push action company upsertemp '["jack", "Jack Sparrow", "[email protected]", "active"]' -p jack@active
Output:
You could use block explorer to inspect the table and the transactions.
Step 2: Perfom an update
Next, we update Jack’s record,
clio push action company upsertemp '["jack", "Jack Nicholson", "[email protected]", "active"]' -p jack@active
Output:
Post-Action Check:
• Inspect Logs to ensure the update was executed. • Inspect Table to see Jack’s updated record.
Step 3: Retrieve all users
clio push action company getallemp '{}' -p jack@active
Ouput:
Step 4: Attempt unauthorized transaction
clio push action company upsertemp '["nick", "Nick Fury", "[email protected]", "active"]' -p jack@active
This should fail since Jack should not be able to add records for other users because the contract enforces proper authorization via require_auth()
.
To insert Nick's record execute the following command:
clio push action company upsertemp '["nick", "Nick Fury", "[email protected]", "active"]' -p nick@active