Mac install Ethernet Square, remix-ide and smart preliminary contract

Mac install Ethernet Square, remix-ide and smart preliminary contract

Prerequisites

  • Installed BREW
    BREW is similar to apt-get, like, easy installation of software on mac.
  • Installation golang
    I used to download the code compiled useless for some time, it is estimated more powerful version of the upgrade. can not be used. Directly with the new brew installed golang.

Installation geth stepped pit

First began to follow the online prompts to install with direct Ethernet brew workshop environment.

brew tap ethereum/ethereum
brew install ethereum 

No problem during installation, the sad story is that the installation is complete execution:

geth version

When tested, we were told executable files illegally, can not be executed. google it, did not result, but more than one person I met, it seems that this version of the problem.
Uninstall things just installed:

brew uninstall ethereum

Then start over, compile the code directly to the clone git:

git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
make geth

no problem. After compilation, execution

./build/bin/geth version

Geth
Version: 1.9.7-unstable
Git Commit: 0ce5e113be8c54c7c30a3a797827114adb0df19c
Git Commit Date: 20191102
Architecture: amd64
Protocol Versions: [64 63]
Network Id: 1
Go Version: go1.13.4
Operating System: darwin
GOPATH=/Users/xxxxx
GOROOT=/usr/local/Cellar/go/1.13.4/libexec

No problem description, the geth link environment to executable directory, such as / user / local / bin:

ln -s /xxxx/build/bin/geth /user/local/bin/geth

It can perform geth started the etheric Square in anywhere.

Initialization Creation Zone

Creation must first initialize the block. Create a new directory as the project directory, and then create a file named in the directory: genesis.json file, as follows:

{
    "nonce": "0x0000000000000042",
    "difficulty": "0x020000",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
    "gasLimit": "0x4c4b40",
    "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "alloc": {}
}

Specific What do you mean I do not know. Find online are almost certain degree to find out, is this the same file. I'll just use.
This file is used to initialize the block creation:

geth init ./genesis.json --datadir ./mychain
WARN [03-21|09:54:38] No etherbase set and no accounts found as default
INFO [03-21|09:54:38] Allocated cache and file handles         database=/Users/jianjiangwang/Desktop/mychain/chain/geth/chaindata cache=16 handles=16
INFO [03-21|09:54:38] Successfully wrote genesis state         database=chaindata                                                 hash=ee3898…ae7194
INFO [03-21|09:54:38] Allocated cache and file handles         database=/Users/jianjiangwang/Desktop/mychain/chain/geth/lightchaindata cache=16 handles=16
INFO [03-21|09:54:38] Successfully wrote genesis state         database=lightchaindata

Parameter --datadir ./mychainis used to specify the data block stored in the directory. Open the mychaindirectory, you can see the gethdirectories and keystoredirectory. Creation area initialization can be considered a success.

Start private chain

Online said, there are two ways to start:

  • method one
geth --datadir ./mychain --nodiscover console 2>>eth_output.log

Parameter Description:

  • -datadir: specifies where the block chain data network
  • console: Start the command line mode, you can execute commands in geth
  • -nodiscover: chain designated as private and will not be seen online
  • >> eth_output.log: expressed eth_output.log to record the output file in the current folder

Execution tail -f eth_output.log, you can see the output log.
This method starts, can only be performed in order to test the command line.

  • Second way
    to perform:
geth --networkid 10 --datadir ./mychain --rpc --rpcapi "admin,debug,eth,miner,net,personal,shh,txpool,web3" --rpcaddr "0.0.0.0" --rpccorsdomain "*" --nodiscover --dev console>>eth.log

Then open another terminal, enter:

geth attach "http://127.0.0.1:8545"

Square Ethernet terminal operation proceeds.
After the start this way and opened the entrance Fi, behind remix-ide installed, online publishing contract, then, this model needs.

Both are normal start-up mode. After starting up, you will find that this chain, not mining . No mining on a lot of things not tested. After all, Ethernet Square make any deal needs to consume gas.
The reason is not mining is said to be sent only when the transaction will be mining.
Continue to find information, find a saying: the new version of -devmodel parameters adds new items:

--dev               Ephemeral proof-of-authority network with a pre-funded developer account, mining enabled
--dev.period value  Block period to use in developer mode (0 = mine only if transaction pending) (default: 0)

It is said that as long as the previous version plus --devyou can perform by miner.start()mining. Anyway, I direct download the latest version does not work, the implementation of return null, according to this explanation is the only mining only when the transaction occurred. But I sent the transaction, they tell me not to do not have gas. So I never get Ethernet currency. Others do not know the actual operation, in the configuration creation area json file may require allocparameters to set a default initial Ethernet currency account of it.

In order to test me as soon as possible, so modify the startup parameters, let him start the mining.

geth --datadir ./mychain --nodiscover --dev --dev.period 1 console 2>>eth_output.log

After starting up, you will find has built a test account, the password is empty. And it has built-in Ethernet huge amount of money. In fact, if regardless of mining, only to have -dev parameter, it will start test mode, there is a default account with an Ethernet massive currency. But each time the service will be shut down to restart the initial state.

Several commonly used commands test

Started gethafter the command console input validation test.
View current account:

> web3.eth.accounts

Create an account, you need to set a password when you create:

> web3.personal.newAccount('123456')
"0xdaa65af5d348c25266a5588148a9c0e9e4c056f8"

Enter a password, the account is returned from a long list.
Then execute web3.eth.accountsthe command, you can see more than one account.
Start mining:
First set of mining account:

> miner.setEtherbase("0xdaa65af5d348c25266a5588148a9c0e9e4c056f8")

Inside the long strings already existing account.
Also:

miner.setEtherbase(eth.accounts[0])

Gets the first account in the list.
It can be performed:

>eth.coinbase

See the current setting of mining accounts is which.
Start mining:

>miner.start()

Stop mining:

>miner.stop()

View account balances:

web3.eth.getBalance(eth.accounts[0])

Eth is the smallest unit wei, 1 ether = 1e18 wei

Initiate transfers. Before the transfer need to unlock the account:

personal.unlockAccount(eth.accounts[0])
personal.unlockAccount(eth.accounts[1])

After unlocking, make transfers:

amount = web3.toWei(5,'ether')
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:amount})

From 0 to 1 Account Account Ethernet switch 5 credits.
Locked account:

personal.lockAccount(eth.accounts[0])
personal.lockAccount(eth.accounts[1])

Here, Ethernet Square test environment basic installation is complete.

Intelligent Remix Solidity IDE installation contract

This thing is full of pits. This thing needs nodejs environment. First with the nodejs brew bottles, but in my attempt, the version number is required, after repeatedly stepped pit, looking for countless pages. And finally install them.
The basic environmental requirements:

$ node -v
v7.10.1
$ npm -v
4.2.0

There are also 8, said node with the line, I did not try. npm version feel little effect, but some say is also a relationship. I originally 6.x, together to drop.
node version is too complicated, but fortunately, provides version management tools n. First installed:

npm install -g n

You can then specify the required version by node n.

sudo n 7.10.1

Can easily specify the version number of the node, the node version of the computer adjust to the needs.
npm version of himself on the line directly npm specify:

npm install npm@4 -g

Other versions of the node, tried many times, either directly npm install or download the code is compiled from git, have failed, mainly all [email protected]this stuff is not installed. After updating node versions, source code compilation is not successful. You can try to download the source code to compile:

git clone https://github.com/ethereum/remix-ide.git
cd remix-ide
npm install
npm start

I installed directly by npm. However, the installation process error, can not find the npxexecution path.
First run:

npm install npx

Then npx link to the executable directory, such as / user / local / bin:

ln -s /usr/local/Cellar/node/12.7.0/bin/npx npx

Probably because I was the first node is 12.7, although I later replaced by n version, but I saw a new package by npm installed, still in 12.7.0 directory. scryptsy scrypt.js

npm install remix-ide -g
remix-ide

However, when running error! ! !
Probably this error:

module.js:442
    throw err;
    ^
Error: Cannot find module './build/Release/scrypt'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)

This melancholy. Continue to find information on similar errors. Installed separately on scrypt:

npm install -g scrypt

After installed, to install the module path remix:

/usr/local/lib/node_modules/remix-ide/node_modules/scrypt/build/Release

Comparative scrypt separately installed, a file found less. From the directory installed separately in this document link over:

link -s /usr/local/Cellar/node/12.7.0/lib/node_modules/scrypt/build/Release/scrypt.node scrypt.node

Run again remix-ide, it's done:

$ remix-ide
setup notifications for /Users/arthurlee/program/ethereum/mychain
Starting Remix IDE at http://localhost:8080 and sharing /Users/arthurlee/program/ethereum/mychain
Tue Nov 05 2019 11:35:45 GMT+0800 (CST) Remixd is listening on 127.0.0.1:65520

Open your browser and enter the http://localhost:8080address: .

Intelligent authoring and publishing contracts

gethAnd remix-ideafter all is installed, start, gethremember to start with the second approach. Open your browser and enter a contract to develop the interface. There have been some examples. Let's engage in a more simple:

pragma solidity ^0.4.18;
contract HelloWorld {
    string msg1;
    
    function HelloWorld(string _msg) public {
        msg1 = _msg;
    }

    function say() constant public returns (string) {
        return msg1;
    }
}

I did not look anything else. But I found a very nasty thing pragma solidity ^0.4.18;this statement this contract what version of solidity to write. Easy to find a moment, there's no complete explanation of how this is defined in this version, it might be some kind of normality. But I do not believe these programs can be compatible version. I saw at least 0.5 to 0.4 and a large different. Him, to do according to this example.

The second is the left toolbar to browse files. Point +symbol. Create a new contract. Since a file name. Copy the contents of the contract in the past.

The third is left of the toolbar to compile. In the Compilerselection and contract corresponding version. Compiled. If wrong, the following error message is displayed. Yes consequently they do not show up.

The first face Details, you can see the content after this contract is compiled. Which WEB3DEPLOYpart is that you can copy it should deploy. This section reads as follows:

var _msg = /* var of type string here */ ;
var helloworldContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"say","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_msg","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var helloworld = helloworldContract.new(
   _msg,
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052341561000f57600080fd5b6040516102b83803806102b8833981016040528080518201919050508060009080519060200190610041929190610048565b50506100ed565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008957805160ff19168380011785556100b7565b828001600101855582156100b7579182015b828111156100b657825182559160200191906001019061009b565b5b5090506100c491906100c8565b5090565b6100ea91905b808211156100e65760008160009055506001016100ce565b5090565b90565b6101bc806100fc6000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063954ab4b214610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc61017c565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101725780601f1061014757610100808354040283529160200191610172565b820191906000526020600020905b81548152906001019060200180831161015557829003601f168201915b5050505050905090565b6020604051908101604052806000815250905600a165627a7a723058201893c1926120c368172f8f8211f6e1a723f12b417d25c83f4982b31ce3ca1d210029', 
     gas: '4700000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

Among them, the contents of the first row of the need to make changes to:

var _msg = /* var of type string here */ ;

After the comment display portion into the desired content, for example hello world.
You can also change:

from: web3.eth.accounts[0], 

Indicate that account to perform this contract.
Ordinarily this content can be copied down to the control terminal directly pasted in the past issued contracts. Adhesive when it should be the equivalent of a line of command will return several times undefined. Do not care.
Finally, if the display:

Contract mined! address: 0x461b37e377da6ff6d73bef4c29142e160a1e4eeb transactionHash: 0x44b68decc1b692369b003cdd6c547b703546274a00653af81015a3ed843476dc

Even if the release succeeds.
Ethernet corresponding account currency will be reduced. After several blocks after the establishment to confirm at this time but may not be able to perform, to wait, approach is to perform transfers, and transfers execution dozen times, then execute:

helloworld.say()

You should be able to succeed.

It can be directly used to publish remix-ide.

Select the toolbar on the left fourth, deployment and operation.
First select environment, select Web3 Provider. It will pop up a window that allows geth enter the address and port. I did not change the default.

http://localhost:8545

If you have questions Rom, you will get an error, but an error message flashed. If there is no problem, the following Accountwill list the account to the current node can be controlled. Choose a modified equivalent

from: web3.eth.accounts[0], 

Then, select Gas Han. In the following Deployinput box edge, just enter something equivalent to amend the

var _msg = /* var of type string here */ ;

But we must remember that both sides of the double quotation marks circled. Otherwise, deployment time will complain:

Unexpected token h in JSON at position 1

Tap Deployto begin deployment. Complete displays similar information:

[block:555 txIndex:0]from:0xcbb...b29dfto:HelloWorld.(constructor)value:0 weidata:0x606...00000logs:0hash:0x3ec...e23f9


You can run.

Which terminal publishing contract can only be executed in its own terminal. Another terminal can not be performed. If you are performing in other terminals, need to come up with a contract address and abi.
When remix-ide deployment, from the lower right corner of Debugthe drop-down arrow next to, point to open, find the deployment address. Then compile the details inside, copy the abi.
Here Insert Picture Description
Then, remove the tab Enter a space and the like, do:

abi=[{"inputs": [{"name": "_msg","type": "uint256"}],"payable": false,"stateMutability": "nonpayable","type": "constructor"},{"constant": true,"inputs": [],"name": "say","outputs": [{"name": "","type": "uint256"}],"payable": false,"stateMutability": "view","type": "function"}]

=Content is copied back out abi.
Then execute:

tt=eth.contract(abi).at("0x692a70D2e424a56D2C6C27aA97D1a86395877b3A")

The contract is a long string of address. Then you can perform this contract:

tt.say()

But how I see there are problems, if the contract is returned uint256, always return 0, in fact, the parameter I set 2.
If a string is directly given:

Error: new BigNumber() not a base 16 Numver:

Checked, it should be web3 the bug. After school look.

other

To an account published contract likely to say no to unlock the account. Unlock time will be displayed:

Error: account unlock with HTTP access is forbidden

If so, increases when you start geth of the following parameters:

--allow-insecure-unlock
Published 20 original articles · won praise 7 · views 2497

Guess you like

Origin blog.csdn.net/cfy_fantasyxx/article/details/102921366