4. BASIC VALUE TYPES
Data Type Example
uint<M> , M=1,2,4, …, 256
int<M>, uint, int
Unsigned/signed integer uint256 counter = 1;
address 160-bit (20byte) value that
does not allow any
arithmetic operations. It is
suitable for storing
addresses of contracts or
keypairs belonging to
external persons.
Address has property
“balance”
address owner =
msg.sender;
If (owner.balance>10) …
bool Same as uint8 but values are
0 or 1
Bool b = 0;
b=true;
fixed<M>x<N>
ufixed<M>x<N>
Signed fixed-point decimal
number of M bits
fixed128x19 f = 1.1;
5. ARRAYS
Data Type Example
bytes1…bytes32, byte Fixed-size byte arrays byte1 bt1= 1;
Byte2 bt2=1;
if (bt2[0]==0) …
bt2.length
byte[N]
uint[N]
bool[N]
…
Fixed-size arrays byte[10] b;
fixed5x19[10] f;
byte[] Dynamic array uint[] memory a = new
uint[](7);
bytes Tightly-packed byte array bytes memory b = new
bytes(123);
string Same as bytes but can not string s=“Hello!”;
6. STRUCTS
pragma solidity ^0.4.11;
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {
address addr;
uint amount;
}
….
uint numFunders = 0;
mapping (uint => Funder) funders;
funders[numFunders++] = Funder({addr: msg.sender, amount: msg.value});
….
}
7. MAPPINGS
pragma solidity ^0.4.11;
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {
address addr;
uint amount;
}
….
uint numFunders = 0;
mapping (uint => Funder) funders;
funders[numFunders++] =
Funder({addr: msg.sender, amount: msg.value});
….
}
mapping(_KeyType => _ValueType)
_KeyType:
any type except mapping, dyn array,
contruct, enum or struct
_ValueType:
any type, including mappings
18. KOVAN TESTNET
Kovan is a Proof of Authority publicly accessible blockchain for
Ethereum; created and maintained by a consortium of Ethereum
developers, to aide the Ethereum developer community.
Connect Get KETH Develop
19. START PARITY AND CONNECT TO
KOVAN
•sudo parity --chain
kovan ui
Etherium
with
Kovan
20. CREATE ACCOUNT ON KOVAN
NETWORK
parity account new --chain kovan
[Remember password and account id]
[Store password in a file for later use]
22. GET SOME ETHER (STEP 1, ASK)
Icarus Faucet (Automated after SMS
Verification)
https://youtu.be/99UucFzYCRc OR
Gitter Channel
https://gitter.im/kovan-testnet/faucet OR
Ask Gene – add comment with your account id
to the message board on
https://www.meetup.com/Blockchain-
Applications-and-Smart-
Contracts/events/tzwnjpyxfbmc/
23. GET SOME ETHER (STEP 2, SYNC
WITH NETWORK)
sudo parity --chain kovan
24. GET SOME ETHER (STEP 3, CHECK
YOUR BALANCE)
sudo geth attach
<path>/io.parity.ethereum/jsonrpc.ipc
account list
>
web3.fromWei(eth.getBalance(eth.coinbas
e), "ether")
50
28. CREATE ERC20 COIN CONTRACT
(SOLIDITY CODE)pragma solidity ^0.4.4;
import "../node_modules/zeppelin-solidity/contracts/token/StandardToken.sol";
/**
* @title RespectCoin
* @dev ERC20 Token example, where all tokens are pre-assigned to th
e creator.
* Note they can later distribute these tokens as they wish using `transfer` and
other
* `StandardToken` functions.
*/
contract RespectCoin is StandardToken {
string public constant name = "RespectCoin";
string public constant symbol = "RESPECT";
uint8 public constant decimals = 18;
uint256 public constant INITIAL_SUPPLY = 10000 * (10 ** uint256(decimals));
/**
* @dev Constructor gives msg.sender all tokens
*/
function RespectCoin() public {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
}
}
34. ERC223 TOKEN
ERC223 is backwards compatible with ERC20
merges the token transfer function among wallets and contracts into
one single function ‘transfer()’
does not allow token to be transferred to a contract that does not
allow token to be withdrawn
35. ERC223 TOKEN INTERFACE
contract ERC223 {
uint public totalSupply;
function balanceOf(address who) public view returns
(uint);
function name() public view returns (string _name);
function symbol() public view returns (string _symbol);
function decimals() public view returns (uint8 _decimals);
function totalSupply() public view returns (uint256
_supply);
function transfer(address to, uint value) public returns
(bool ok);
function transfer(address to, uint value, bytes data) public
returns (bool ok);
function transfer(address to, uint value, bytes data, string
custom_fallback) public returns (bool ok);
event Transfer(address indexed from, address indexed to,
uint value, bytes indexed data);
36. ERC721
People love collecting
Allow smart contracts to operate as tradable tokens
Each ERC721 is unique (non-fungible)
Support “ownership” functions
Each token is referenced by unique id
Tokens can have metadata (attributes)
37. ERC721
contract ERC721 {
event Transfer(address indexed _from, address
indexed _to, uint256 _tokenId);
event Approval(address indexed _owner, address
indexed _approved, uint256 _tokenId);
function balanceOf(address _owner) public view
returns (uint256 _balance);
function ownerOf(uint256 _tokenId) public view
returns (address _owner);
function transfer(address _to, uint256 _tokenId)
public;
function approve(address _to, uint256 _tokenId)
public;
38. STAY IN TOUCH
Gene Leybzon https://www.linkedin.com/in/leybzon/
https://www.meetup.com/members/90744
20/
https://www.leybzon.com