42
SMART CONTRACTS THE FIRST ENCOUNTER

Smart Contracts. Pierwsze starcie

Embed Size (px)

Citation preview

Page 1: Smart Contracts. Pierwsze starcie

SMART CONTRACTS THE FIRST ENCOUNTER

Page 2: Smart Contracts. Pierwsze starcie

SMART CONTRACTS - THE FIRST ENCOUNTER

AGENDA

▸ SMART CONTRACT - WHAT IS IT?

▸ SOLIDITY

▸ DEV ENVIRONMENT

▸ SIMPLE SMART CONTRACT

▸ TESTING

▸ PROBLEMS

▸ QUESTIONS

Page 3: Smart Contracts. Pierwsze starcie

ADAM POLAK PHP DEVELOPER

JS DEVELOPER

E2E DEVELOPER

[email protected]

POLAK.ADAM1

Page 4: Smart Contracts. Pierwsze starcie

LOOKING FOR AWESOME NODE.JS DEVS

Page 5: Smart Contracts. Pierwsze starcie

SMART CONTRACT

Page 6: Smart Contracts. Pierwsze starcie

SMART CONTRACT - WHAT IS IT?

IT’S A CONTRACTBUT IN BLOCKCHAIN

Page 7: Smart Contracts. Pierwsze starcie

SMART CONTRACT - WHAT IS IT?

▸ NOT ONLY ABOUT TRANSFERS

▸ WRITTEN IN SOLIDITY

▸ CONTAINS BUSINESS LOGIC

▸ TRANSACTION BASED

ETHEREUM SMART-CONTRACTS

Page 8: Smart Contracts. Pierwsze starcie

SMART CONTRACT - WHAT IS IT?

ETH SMART-CONTRACTaddResource(price, url)

accessUrl hasAccess

getAccess(price)

Page 9: Smart Contracts. Pierwsze starcie

SOLIDITY

Page 10: Smart Contracts. Pierwsze starcie

SOLIDITY

SMART-CONTRACTS IMPLEMENTING

LANGUAGE

Page 11: Smart Contracts. Pierwsze starcie

SOLIDITY

pragma solidity ^0.4.4;

contract HelloUszanowanko { string private message;

function HelloUszanowanko() public { message = 'Hello TSH'; }

function getMessage() constant public returns(string) { return message; }

function setMessage(string newMessage) public { message = newMessage; } }

Page 12: Smart Contracts. Pierwsze starcie

SOLIDITY

COMMANDS COST GAS

Page 13: Smart Contracts. Pierwsze starcie

SOLIDITY

QUERIES ARE FREE

Page 14: Smart Contracts. Pierwsze starcie

DEV ENVIRONMENT

Page 15: Smart Contracts. Pierwsze starcie

DEV ENVIRONMENT

▸ SMART-CONTRACT COMPILATION

▸ DEPLOYMENT

▸ CONSOLE

▸ EASIER TESTING

ETHEREUM DEVELOPMENT FRAMEWORK

Page 16: Smart Contracts. Pierwsze starcie

LOCAL BLOCKCHAIN

Page 17: Smart Contracts. Pierwsze starcie

LOCAL BLOCKCHAIN

Page 18: Smart Contracts. Pierwsze starcie

TRUFFLE-CLI

Page 19: Smart Contracts. Pierwsze starcie

DEV ENVIRONMENT

Page 20: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

Page 21: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

truffle init

truffle create contract HelloUszanowanko

pragma solidity ^0.4.4;

contract HelloUszanowanko { function HelloUszanowanko() public { // constructor } }

npm i -g truffle

Page 22: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

pragma solidity ^0.4.4;

contract HelloUszanowanko { string private message;

function HelloUszanowanko() public { message = 'Hello TSH'; }

function getMessage() constant public returns(string) { return message; }

function setMessage(string newMessage) public { message = newMessage; } }

Page 23: Smart Contracts. Pierwsze starcie

MIGRATION

Page 24: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

truffle create migration HelloUszanowanko

module.exports = function(deployer) { // Use deployer to state migration tasks. };

const HelloUszanowanko = artifacts.require('HelloUszanowanko');

module.exports = function(deployer) { deployer.deploy(HelloUszanowanko); };

truffle migrate

Page 25: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

OOPS! FAIL!

Page 26: Smart Contracts. Pierwsze starcie

NETWORK CONFIG

Page 27: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

module.exports = { networks: { development: { host: "127.0.0.1", port: 7545, network_id: "5777" } } };

Page 28: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

Page 29: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

truffle console

Page 30: Smart Contracts. Pierwsze starcie

FIRST CONTRACT

Page 31: Smart Contracts. Pierwsze starcie

TESTING

Page 32: Smart Contracts. Pierwsze starcie

TESTING

truffle create test HelloUszanowanko

contract('HelloUszanowanko', function(accounts) { it("should assert true", function(done) { var hello_uszanowanko = HelloUszanowanko.deployed(); assert.isTrue(true); done(); }); });

truffle test

Page 33: Smart Contracts. Pierwsze starcie

TESTING

OOPS! FAIL! AGAIN!

Page 34: Smart Contracts. Pierwsze starcie

TESTING

const HelloUszanowanko = artifacts.require(‘HelloUszanowanko’);

contract(‘HelloUszanowanko', function(accounts) { it("should assert true", function(done) { var hello_uszanowanko = HelloUszanowanko.deployed(); assert.isTrue(true); done(); }); });

truffle test

Page 35: Smart Contracts. Pierwsze starcie

TESTING

Page 36: Smart Contracts. Pierwsze starcie

TESTING

const HelloUszanowanko = artifacts.require('HelloUszanowanko');

contract('HelloUszanowanko', function(accounts) { it('has default message', async function() { const contract = await HelloUszanowanko.deployed(); const message = await contract.getMessage(); assert.equal(message, 'Hello TSH', 'Hello TSH is message'); });

it('changes message', async function() { const contract = await HelloUszanowanko.deployed(); await contract.setMessage('Hello Uszanowanko'); const message = await contract.getMessage(); assert.equal(message, 'Hello Uszanowanko', 'Hello Uszanowanko is message'); }); });

truffle test

Page 37: Smart Contracts. Pierwsze starcie

TESTING

Page 38: Smart Contracts. Pierwsze starcie

DECENTRALIZED APPS

SOON

Page 39: Smart Contracts. Pierwsze starcie

PROBLEMS

Page 40: Smart Contracts. Pierwsze starcie

PROBLEMS

▸ IMMATURE TOOLS

▸ STEEP LEARNING CURVE

▸ DECENTRALIZED APPS ARE SLOW

▸ EASY TO LOSE MONEY

Page 41: Smart Contracts. Pierwsze starcie

QUESTIONS ?

SMART CONTRACTS - THE FIRST ENCOUNTER

Page 42: Smart Contracts. Pierwsze starcie

THANK YOU