Coder Social home page Coder Social logo

solidity-greeter's Introduction

Getting started with Solidity

(WIP) Clean up documentation and understand what's happening...

Installation on macOS

brew tap ethereum/ethereum
brew install solidity
which solc

Installing Geth

$ brew tap ethereum/ethereum
$ brew install ethereum
$ geth # starts the server

Creating account

Create an account first. For more info, see here.

$ geth account new

Starting the interactive JavaScript environment

$ geth console

Now you can do stuff with eth and admin.

Linking your compiler in Geth

$ which solc # get the path/to/solc
$ admin.setSolc("path/to/solc")

Compile soliditity contracts with Geth v1.6

Other solutions here

# To generate bytecode:
$ solc --bin soliditySource.sol

# To generate ABI:
$ solc --abi soliditySource.sol

Then, with your newly generated bytecode and abi, in geth 1.6:

 var abi = <abi from solc>;
 var myContract = eth.contract(abi); 
 var bytecode = '0x' + <bytecode from solc>;
 var txDeploy = {from:eth.coinbase, data: bytecode, gas: 1000000}; 
 var myContractPartialInstance = myContract.new(txDeploy); 

 // Mine block containing transaction...

 var myContractInstance = myContract.at(myContractPartialInstance.address);

Connecting web3 to geth

For localhost:

$ geth --rpc  --rpccorsdomain="*" --rpcaddr="localhost" console 2>> geth.log

In your javascript file with script pointing to dist/web3.min.js, include:

web3.setProvider(new web3.providers.HttpProvider());
// or
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'));

Use testrpc for testing

$ testrpc --secure -u 0 -u 1

You may have to "unlock" the account that is sending the transaction using the password you picked in the beginning, because you need to pay for the gas costs to deploying your contract: e.g.

# At geth console 
$ personal.unlockAccount(web3.eth.accounts[0], "yourPassword")

check current block gas limit by running - eth.getBlock("latest"). If you supply more gas than this value, you will face 'Exceeds block gas limit' error

Start mining

# Start mining at the test network
$ geth --testnet --datadir "~/.ethereum-testnet" --mine console 2>> ~/.ethereum-testnet.log

# Log the results
$ tail -f ~/.ethereum-testnet.log

# Check your balance
$ web3.fromWei(eth.getBalance(eth.coinbase), "ether")

Check your coinbase account

# Check account
$ web3.eth.coinbase

# Select the account you want to mine, e.g. account 0
$ web3.miner.setEtherbase(web3.eth.accounts[0])

# Unlock it before mining
$ personal.unlockAccount(web3.eth.accounts[0], "yourPassword")

# mine with 4 threads
$ miner.start(4)

# Check your balance
$ web3.fromWei(eth.getBalance(eth.coinbase), "ether")

solidity-greeter's People

Contributors

alextanhongpin avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.