This section of the guide provides instructions for sending actions to an external contract. The examples of the execution of instructions are shown in the contract, where the performed actions are kept.
8.1 Addressbook counter address contract
Log into CONTRACTS_DIR and create a directory there with the name abcounter, as well as the file abcounter.cpp.
cd CONTRACTS_DIR
mkdir abcounter
cd abcounter
touch abcounter.cpp
Open the abcounter.cpp file and write the following program text into it:
The peculiarity of this text is that it has a restriction on calls to an action for the contract account. For restriction, use require_auth for the addressbook contract. Only the addressbook contract account is authorized to perform require_auth. The count action is not sent by the user, but by the addressbook contract.
8.6.3 Check that the upsert method modifies the record.
cleos push action addressbook upsert '["alice", "alice", "liddell", 21,"1 there we go", "wonderland", "amsterdam"]' -p alice@active
The actions are considered successfully completed if the resulting output contains the following information:
executed transaction: …
# addressbook <= addressbook::upsert {"user":"alice","first_name":"alice","last_name":"liddell","street":"1 coming down","city":"normalla...
# addressbook <= addressbook::notify {"user":"alice","msg":"alice successfully emplaced record to addressbook"}
>> Notified
# alice <= addressbook::notify {"user":"alice","msg":"alice successfully emplaced record to addressbook"}
# abcounter <= abcounter::count {"user":"alice","type":"emplace"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
8.6.4 Verify the liquidation of the alice user entry from the table by running:
The action is considered to be successfully completed if the resulting output contains the following information:
executed transaction: ...
# addressbook <= addressbook::erase {"user":"alice"}
>> Erased
# addressbook <= addressbook::notify {"user":"alice","msg":"alice successfully erased record from addressbook"}
>> Notified
# alice <= addressbook::notify {"user":"alice","msg":"alice successfully erased record from addressbook"}
# abcounter <= abcounter::count {"user":"alice","type":"erase"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
Toaster:addressbook sandwich$
8.6.5 Test the ability to manipulate abcounter contract data by executing:
cleos push action abcounter count '["alice", "erase"]' -p alice@active
cleos get table abcounter abcounter counts --lower alice
The abcounter contract table should contain the following information: