Ethereum Introductory Learning Notes
Published in: Blockchain Project navigation:
The default installation completes the Ubuntu16.04 environment first.
Note: To obtain the root user, follow these steps:
sudo passwd-u root
Enter password
sudo passwd root
Set the root user password
Install the necessary environment
Git
sudo apt-get install git
Jump out of dialog input: Y (similar below)
View git version after installation is complete
git version
Curl
Installing Curl
sudo apt-get Install Curl
CURL-SL https://deb.nodesource.com/setup_6.x | SUDO-E Bash
NodeJS
Installing Nodejs
sudo apt-get install-y Nodejs
View Nodejs version after installation is complete
Nodejs-v
Npm
Installing NPM
sudo apt-get install NPM
View the NPM version after installation is complete
Npm-v
Solc
Installing SOLC and SOLC-CLI
sudo npm install-g solc solc-cli--save-dev
Truffle
Installing truffle
sudo npm install-g Truffle
View version after installation is complete
Truffle version
Testrpc
sudo npm install-g ethereumjs-testrpc
Geth
Installing Geth
sudo add-apt-repository-y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install Ethereum
View version information after installation is complete
Geth version
Go (optional)
Installing Golang
wget https://storage.googleapis.com/golang/go1.10.1.linux-amd64.tar.gz
sudo tar-c/usr/local-xzf go1.10.1.linux-amd64.tar.gz
Configuring Environment variables
CD ~ VI.BASHRC
Export Goroot=/usr/local/go
Export Gopath= $HOME/go
Export path= $PATH: $GOROOT/bin: $GOPATH/bin
Installation Complete View version
Go env
Go version
Web3
Installing WEB3
NPM Install web3@^0.20.0
Ganache
Installing ganache
wget https://github.com/trufflesuite/ganache/releases/download/v1.0.1/ganache-1.0.1-x86_64.AppImage
Chmod-x Ganache-1.0.1-x86_64.appimage
./ganache-1.0.1-x86_64.appimage
After installation is complete
Configure startup
Initializing the Genesis block
Select the directory to create the Genesis.json file and edit save.
{
"Config": {
"Chainid": xxxx (modify any number),
"Homesteadblock": 0,
"Eip155block": 0,
"Eip158block": 0
},
"Alloc": {},
"Coinbase": "0x0000000000000000000000000000000000000000",
"Difficulty": "0x20000" (to modify the difficulty value, easy to dig ore),
"Extradata": "",
"Gaslimit": "0x2fefd8",
"Nonce": "0x0000000000000042",
"Mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"Parenthash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"Timestamp": "0x00"
}
Mixhash: With the nonce for mining.
Nonce: With Mixhash to dig mine.
Difficulty: Set the difficulty of the current block (set a small point here, easy to dig ore).
Alloc: Used to set the number of ethereum ether tokens for accounts and accounts.
Coinbase: Miner's account number.
Timestamp: timestamp.
Parenthash: The hash value of the previous chunk, this is the Genesis block so it is 0.
Extradata: Additional information.
GASLIMIT:GASG the total consumption setting.
Run command initialization after completion:
Geth Init directory/genesis.json
Output after completion
Start a private chain
Geth--identity "Onetesteth"--rpccorsdomain "*"--nodiscover--rpcapi "*"--cache=1024--networkid 9999 Console
Describes the function of each parameter:
Nodiscover Use this command to make sure that your nodes are not being discovered by people who are not manually added by you. Otherwise, your node may be accidentally added by a stranger's blockchain because you have the same creation file and network ID as you do.
Maxpeers 0 If you don't want other people to connect to your test chain, you can use Maxpeers 0. Conversely, if you know exactly how many people you want to connect to your node, you can do so by adjusting the numbers.
RPC can activate the RPC service for your node. It is usually activated by default in Geth.
Rpcapi "DB,ETH,NET,WEB3" determines which APIs are allowed to open the RPC service. By default, only the WEB3 API is activated.
Rpcport "8080" changes 8000 to any port that is open on your network. The default setting for Geth is 8080.
Rpccorsdomain "https://xxxx.com" This can indicate what URL can be connected to your node to perform RPC custom-end tasks. Be careful to enter a specific URL instead of wildcard (*), which causes all URLs to connect to your RPC instance.
DataDir "/home/testchain1" This is the data directory where your private chain data is stored (under Nubits). Choose a location that is separate from your Ethereum public chain folder.
Identity "Testnetmainnode" This will set an identity for your node, making it easier to identify in the endpoint list. This example shows how these identities appear on the network.
Networkid 1999 Number type, differentiate with other network ID, Ethernet id=1 network. Must differentiate, in order to place the purse and so mistakenly think is the ether square public chain. 2=morden (disused), 3=ropsten, 4=rinkeby, default is 1.
Port 30303-PEER network listening port, default 30303.
Fast This command is Geth1.6.0 and will only be changed to--syncmode=fast, but the command continues to work. Configuring this command enables fast synchronization of chunks.
The CACHE=1024 program contains the available memory, in megabytes. The default is 16MB (minimum value). Can be configured according to the server capacity to 1GB, or 2048 (2GB).
Create an unlocked account
Create an Account
Personal.newaccount ("Jacky")
Personal.newaccount ("Bill")
Unlock Account
Personal.unlockaccount (Eth.accounts[1], "Jacky");
True
Personal.unlockaccount (eth.accounts[2], "Bill");
True
Digging mine
Start digging mine.
Miner.start (1) A thread digs a mine
Stop Digging mine
Miner.stop ()
General transfer
Eth.sendtransaction ({from: ' Sender ', to: ' Recipient ', Value:web3.toWei (1, ' Ether ')})
May encounter lock, then unlock the default account
Personal.unlockaccount ("Account", "password", 300)
Common commands:
View account: Eth.accounts
View Balance: Web3.fromwei (eth.getbalance (account), "ether")
Deployment contract
Http://remix.ethereum.org edit the code on the left here:
pragma solidity ^0.4.21;
Contract Hello {
string greeting;
function Hello (string _greeting) public {
greeting = _greeting;
}
function say () constant public Returns (string) {
return greeting; }
}
The right details generate the deployment code, the dialog pops up, select the web3deploy-copy, and paste it into the local text editor for modification.
var _greeting = "Hello Ethereum";
var hellocontract = Web3.eth.contract ([{"Constant": true, "inputs": [], "name": "Say", "outputs": [{"Name": "", "type": " String "}", "payable": false, "statemutability": "View", "type": "function"},{"inputs": [{"Name": "_greeting", "type": " String "}]," payable ": false," statemutability ":" Nonpayable "," type ":" Constructor "}]);
var hello = hellocontract.new (
_greeting,
{
FROM:WEB3.ETH.ACCOUNTS[2],
Data: ' 0x608060405234801561001057600080fd5b506040516102a83803806102a883398101806040528101908080518201929190505050806000908051906 0200190610049929190610050565b50506100f5565b828054600181600116156101000203166002900490600052602060002090601f01602090048101 9282601f1061009157805160ff19168380011785556100bf565b828001600101855582156100bf579182015b828111156100be5782518255916020019 190600101906100a3565b5b5090506100cc91906100d0565b5090565b6100f291905b808211156100ee5760008160009055506001016100d6565b5090 565b90565b6101a4806101046000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000 000000000900463ffffffff168063954ab4b214610046575b600080fd5b34801561005257600080fd5b5061005b6100d6565b60405180806020018281 03825283818151815260200191508051906020019080838360005b8381101561009b578082015181840152602081019050610080565b5050505090509 0810190601f1680156100c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6060600080546001 81600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029 004801561016e5780601f106101435761010080835404028352916020019161016e565b820191906000526020600020905b8154815290600101906020 0180831161015157829003601f168201915b50505050509050905600a165627a7a723058206b801e5b597ecc38167442c7a44a761b128cd92cf19d6a1 53f7c0a2caab455ba0029 ',
Gas: ' 1700000 '
}, function (e, contract) {
Console.log (e, contract);
if (typeof contract.address!== ' undefined ') {
Console.log (' Contract mined! Address: ' + contract.address + ' Transactionhash: ' + Contract.transactionhash ');
}
})
Modified to deploy to the local ethereum environment.
In case of no error, the contract deployment is complete, then in the console console:
Hello.say ()
Output: Hello Ethereum