Ethereum and Blockchain. - michaelchen0426/knowledge-sharing GitHub Wiki
Getting Started
How to run the Ethereum scripts
The smart contract is written by Solidity and we used Ethereum for our blockchain development. Key components are:
- Geth as our ethereum client node. Details are here https://github.com/ethereum/go-ethereum/wiki/geth.
- solc-js as our Solidity complier. Details are here https://github.com/ethereum/solc-js.
- Ropsten as our testnet of Blockchain.
- Remix is a good online Ethereum IDE. We can try our script and connect to test account.
Firstly, we need to install all above components:
Install Solidity Compiler in macOs:
Details are https://solidity.readthedocs.io/en/v0.5.3/installing-solidity.html. Use brew to install,
brew tap ethereum/ethereum
brew install solidity
Compile Smart Contract
Use solc-js to compile Solidity code. It will generate json file which contains ABI, Bin and MetaData.
cd ./Ethereum
solc --combined-json=abi,bin,metadata --output-dir . player.sol
Install Geth
Full details are here https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac.
Clone the repository to a directory of your choosing:
git clone https://github.com/ethereum/go-ethereum
Building geth requires the Go compiler:
brew install go
Finally, build the geth program using the following command.
cd go-ethereum
make geth
If you see some errors related to header files of Mac OS system library, install XCode Command Line Tools, and try again.
xcode-select --install
Connect Geth to Ropsten testnet.
Geth --testnet --rpc -rpcapi=”eth,net,web3,personal,txpool” --syncmode=light
Attach Geth client to localhost
geth attach http://127.0.0.1:8545
After we run above command, we are able to connect to Geth client via JS code by using the url http://127.0.0.1:8545 in our script.
Create and Deploy Smart Contract
cd ./Ethereum
npm install
node deploy.js
Sample Smart Contract Link: https://ropsten.etherscan.io/address/0x2bc235b4e4bde64cb70ba5f277ccfeffea8f2557