Mike Haggerty: Blockchain - A Walk Around the Block
“A Walk Around the Block” – Miners and smart contracts and hard forks, OH MY! The explosion of cryptocurrency has brought with it a host of new technology and terminology. The first half of this presentation will focus on giving a rudimentary introduction to blockchain technology in general: how it works and why it matters. In the second half, a specific blockchain software system – EOS.IO – will be used to standup a new blockchain network and deploy a simple smart contract written in C++.
- https://nadejde.github.io/eos-token-sale/
- copy and paste keypair somewhere for reference.
- https://monitor.jungletestnet.io/#account
- use the same public key for owner and active.
- account name must be 12 characters [a-z,1-5]
- https://jungle.bloks.io/
- search for account name or public key
https://developers.eos.io/eosio-home/docs/setting-up-your-environment
brew tap eosio/eosio
brew install eosio
brew tap eosio/eosio.cdt
brew install eosio.cdt
wget https://github.com/eosio/eos/releases/download/v1.6.0/eosio_1.6.0-1-ubuntu-16.04_amd64.deb
sudo apt install ./eosio_1.6.0-1-ubuntu-16.04_amd64.deb
wget https://github.com/EOSIO/eosio.cdt/releases/download/v1.4.1/eosio.cdt-1.4.1.x86_64.deb
sudo apt install ./eosio.cdt-1.4.1.x86_64.deb
cleos -u https://jungle2.cryptolions.io get info
- Compare the data from cleos and bloks: https://jungle.bloks.io/chain
- Head block is the one just produced; 2 blocks per second.
- The last irreversible block lags behind because 15/21 block producers must have produced a derived block.
cleos wallet create --to-console
cleos wallet unlock
cleos wallet import
- What is a wallet? Does it store crypto assets? No. Just stores keypairs.
cleos -u https://jungle2.cryptolions.io transfer mphfoofoo123 mphfoofoo321 "27 EOS"
cd ~
mkdir contracts
cd contracts
mkdir hello
cd hello
touch hello.cpp
- Copy contents of hello.cpp to local file.
eosio-cpp -o hello.wasm hello.cpp --abigen
Did you get an Error: `GLIBCXX_3.4.22' not found (Ubuntu 16.04)?
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get upgrade libstdc++6
Check output
cat hello.abi
cat hello.wasm
- What is Web Assessmbly?
- Designed to run wasm in JavaScript, but EOSIO is running the wasm from C++ VM.
- wasm is a compile target for dozens of languages
cleos -u https://jungle2.cryptolions.io set contract mphfoofoo123 ~/dev/walk-block/contracts/hello -p mphfoofoo123@active
Did you get an insufficient ram error?
cleos -u https://jungle2.cryptolions.io system buyram mphfoofoo123 mphfoofoo123 "10 EOS"
- EOS requires accounts to buy RAM to store their smart contracts
cleos -u https://jungle2.cryptolions.io push action mphfoofoo123 hi '["mphfoofoo123"]' -p mphfoofoo123@active
- The user argument can be any text that conforms to EOS account name specifications. It doesn't have to be a valid account.
- Try passing a fake account - the contract will still say hello.
eosio_assert( is_account( user ), "user account does not exist");
- Add the above line to hello.cpp
- Recompile and deploy
- Now only valid accounts will be greeted.
wget https://raw.githubusercontent.com/EOSIO/eosio.contracts/master/eosio.token/include/eosio.token/eosio.token.hpp
wget https://raw.githubusercontent.com/EOSIO/eosio.contracts/master/eosio.token/src/eosio.token.cpp
- Edit eosio.token.cpp. Change line 6 to
#include "eosio.token.hpp"
- Copy contents of hello2.cpp to local file.
- Recompile and deploy
- Add below lines to contract method
- Recompile and deploy
if(b.amount > 5000000) {
print(" || You are rich! Go away, ", user);
} else {
print(" || Hello, ", user);
}