(WIP) Clean up documentation and understand what's happening...
brew tap ethereum/ethereum
brew install solidity
which solc
$ brew tap ethereum/ethereum
$ brew install ethereum
$ geth # starts the server
Create an account first. For more info, see here.
$ geth account new
$ geth console
Now you can do stuff with eth
and admin
.
$ which solc # get the path/to/solc
$ admin.setSolc("path/to/solc")
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);
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 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 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")