EOS developer - HelloWorld - Interact with your contract

in #eos6 years ago

Interact with your first HelloWorld smart contract on EOS

To follow along you will need to create that contract : https://steemit.com/helloworld/@leander/eos-developer-first-contract-helloworld

And get a EOS local account : https://steemit.com/cleos/@leander/eos-developer-on-macos-up-and-running-all-the-i-had-issues-and-how-i-fixed-them

Now that you have your blockchain up, your contract running and your account registered let's continue

Now we need to import our wallet like this (without the curly braces) :

cleos wallet import -n mywallet {your private key}

Next we are going to create a new account for the blockchain

cleos create account eosio hello.code {your public key} {your public key}

it's time to set our contract using all we previously made:

where hello.code is the name of the contract owner
. is the current directory (containing the 2 files, .wasp and .abi)
-p flag stands for permission followed by the account name giving that permission.

cleos set contract hello.code . HelloWorld.wasp HelloWorld.abi -p hello.code

Interacting with our HelloWorld contract

We can now interact with the contract by pushing actions to the account

cleos push action: is the way to access any contract in our local blockchain
hello.code is the name of the account linked to the HelloWorld contract
hello is the name we gave to the function in the HelloWorld class
'["satochi"]' is the argument passed in our hello function. It can be replaced by any name, lowercase, less than 13 characters
-p for permission
mywallet or hello.code, both would work. It just needs an account to grant permission

cleos push action hello.code hello '["satoshi"]' -p mywallet

you should see something like this :

executed transaction: bd0dfbb48432b831f5e02d5b05bfa7ab00bedc4c17f44738a80b06ca3b661902  104 bytes  259 us
#    hello.code <= hello.code::hello            {"user":"satoshi"}
>> Hello, satoshi
Sort:  

@leander, I gave you a vote!
If you follow me, I will also follow you in return!

Congratulations @leander! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.21
TRX 0.25
JST 0.038
BTC 95300.27
ETH 3336.41
USDT 1.00
SBD 3.10