EOSIO - How to use Smart Contracts

in #eosio6 years ago

EOSIO Basic Operations

Image of EOSIO

If you are a developer trying to run the [Getting Started with Smart Contracts] (https://developers.eos.io/eosio-cpp/docs/introduction-to-smart-contracts) you can follow the next tutorial using a docker image:

  1. Get the docker image from repository using the next command:
      $ docker pull eosio/eos-dev
    
  1. Start the EOSIO node.
      $ sudo docker run --rm --name eosio -d -p 8888:8888 -p 9876:9876 -v /tmp/work:/work -v /tmp/eosio/data:/mnt/dev/data -v /tmp/eosio/config:/mnt/dev/config eosio/eos-dev  /bin/bash -c "nodeos -e -p eosio --plugin eosio::wallet_api_plugin --plugin eosio::wallet_plugin --plugin eosio::producer_plugin --plugin eosio::history_plugin --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin --plugin eosio::http_plugin -d /mnt/dev/data --config-dir /mnt/dev/config --http-server-address=0.0.0.0:8888 --access-control-allow-origin=* --contracts-console"
    
    
  1. Start the keosd service (is needed for can create the wallets and the accounts)
       $ docker exec eosio keosd --http-server-address=localhost:8899
    
  1. Open a new tab or a new terminal window and set the alias for can use cleos
       $ alias cleos='docker exec eosio /opt/eosio/bin/cleos --wallet-url http://localhost:8899'
    
  1. Create a new wallet on EOSIO using the next command ( by default use the name default )
       $ cleos wallet create
    
  1. Import a new Key into the wallet
       $ cleos wallet import 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
       - [ OUTPUT ] -
       imported private key for: EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
    
  1. Load the BIOS contract using the eosio account (eosio account is the default account available on EOSIO image)
      $ cleos set contract eosio contracts/eosio.bios -p eosio@active
    

Creating a new account

  1. First create a key

      $ cleos create key
      - [ OUTPUT ] -
       Private key: 5Jmsawgsp1tQ3GD6JyGCwy1dcvqKZgX6ugMVMdjirx85iv5VyPR
       Public key: EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
      
    
  2. Then import this key into our wallet

     $ cleos wallet import 5Jmsawgsp1tQ3GD6JyGCwy1dcvqKZgX6ugMVMdjirx85iv5VyPR
      - [ OUTPUT ] -    
       imported private key for: EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
    
  3. Create an account called user

      $ cleos create account eosio user EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
    
  4. Create an account called tester

      $ cleos create account eosio tester EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
    

TESTING EOSIO TOKEN CONTRACT

Creating a new account

  1. First create one new account
      $ cleos create account eosio eosio.token \
       EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 \
       EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4
    
  1. Deploy the eosio.token smart contract
      $ cleos set contract eosio.token /contracts/eosio.token -p eosio.token@active
    
  1. Call to the method create of eosio.token Smart Contract

      $ cleos push action eosio.token create '[ "eosio", "1000000000.0000 SYS"]' \
        -p eosio.token@active
    

    or try the next for verbose mode

  ```bash
    $ cleos push action eosio.token create \
    '{"issuer":"eosio", "maximum_supply":"1000000000.0000 SYS"}' \
    -p eosio.token@active
  ``
  1. Issue Tokens to Account "User"
      cleos push action eosio.token issue '[ "user", "100.0000 SYS", "memo" ]' \
       -p eosio@active
    
  1. Transfer Tokens to Account "Tester"

      $ cleos push action eosio.token transfer \
       '[ "user", "tester", "25.0000 SYS", "m" ]' -p user@active
    

All the above instructions allow you use and understand the creation of keys, how to create accounts and how to deploy a smart contract, using the docker image.

Let me know any issue you have.

Sort:  

Congratulations @gartoxmx! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You made your First Vote
You got a First Vote

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Croatia vs England


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Vamos a probar

Que tal si te funciono?

Congratulations @gartoxmx! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

You made your First Comment

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Semi Finals - Day 1


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

I think there are some things that could go into the article. Maybe do a spanish version, and also add some of the returns from the command line when inserting the contracts.

executed transaction: bd22bd2ec9ee06c01e793cbcc1c6d58c154baa37a0e363890738849a38ca19ee  3720 bytes  10148 us
warning: transaction executed locally, but may not be confirmed by the network yet
#         eosio <= eosio::setcode               {"account":"eosio","vmtype":0,"vmversion":0,"code":"0061736d0100000001621260037f7e7f0060057f7e7e7e7e...
#         eosio <= eosio::setabi                {"account":"eosio","abi":"0e656f73696f3a3a6162692f312e30050c6163636f756e745f6e616d65046e616d650f7065.

I get that as output when inserting the bios contracts. Great article thought.

Congratulations @gartoxmx! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

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.29
TRX 0.11
JST 0.033
BTC 63458.69
ETH 3084.37
USDT 1.00
SBD 3.99