Skip to content

sid226/ethereum_training

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Hands on:

Geth install:

https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

Managing accounts:

https://github.com/ethereum/go-ethereum/wiki/Managing-your-accounts

geth console

# new account
geth account new

geth account list

Test Network tool:

https://github.com/trufflesuite/ganache-cli

sudo npm install -g ganache-cli

Browser-compiler solidity:

http://remix.ethereum.org/#optimize=true&version=soljson-v0.4.24+commit.e67f0147.js

Sample smart contract:

pragma solidity ^0.4.22;

contract Simple
{
    uint a;

    constructor () public {
        a=10;
    }

    function  getData() public constant returns(uint)
    {
        return a;
    }

    function setData(uint x) public returns(bool)
    {
        a=x;
    }

}

Interact with Smart Contract with javascript

Install node:

https://github.com/creationix/nvm

nvm install 8.0.0

#Check node and npm  version
node -v
npm -v

Install web3

npm install [email protected]

Docs

Sample javascript :

var Web3= require('web3')

  web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

console.log(web3.version)

console.log(web3.eth.accounts)

abi= < Add ABI from remix here >


address=<Add Deployed contract address here> ; //'0xe8081a3fc2e0a93c2bbfbb392540e503f56297d3'


// creation of contract object
var myContract = web3.eth.contract(abi).at(address)

//call the getData function our contract
myContract.getData.call(function (err, result) {
if (err) { console.log(err) }
console.log(result);

});



//call the setData function our contract
myContract.setData.sendTransaction(100, { from: web3.eth.accounts[0], gas: 4000000 }, function (error, result) {
if (!error) {
console.log(result);
} else {
console.log(error);
}
})

About

training material

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published