Ethernet Square under Windows Integrated Development Environment (Remix-IDE) to build a simple application intelligence contract

In front of us the Square platform Ethernet private development block chain process chain, as well as mining operations in the private chain, and with the development of technology block chain, block chain technology is not limited to use Bitcoin the future will focus on the expansion of focusing extended to other areas, in order to open the block chain intelligence contracts represented 2.0 times. This selection of remix as a development platform for applications, with the geth clients interact with the Ethernet network Square, next article will be used instead to build ganache truffle and development framework (which is something).

This article is divided remix-ide contract to build and deploy intelligent application of two parts.

A, remix-ide build

【Ready to work】

1. Install Node.js. Node provides a JavaScript runtime environment, and contains a large number of expansion modules divided into different functions simplify application development.

① node.js download from the following URL, and install one step to your specified folder according to the instructions step:

https://nodejs.org/en/download/

② After installation is complete, open operating environment, type cmd to enter DOS command input:

node --version

 

 It means that the node is installed successfully.

2.node.js After successful installation, the installation position of the folder that contains the content is as follows:

 

 Visible node is included npm management tools, we have used here is npm package to download third-party server function for local use.

[Build] remix

After good preparation, we started to build a remix environment.

1. Download the remix to the machine:

(To establish a separate folder, such traceability downloaded files) into the new folder, command input:

git clone https://github.com/ethereum/remix-ide.git

2. After a successful download generates multiple folders in the folder, wherein the folder comprises a remix-ide, into the folder:

cd remix-ide

Subsequently required for installation kit:

npm install 

Execution start command:

Elevation start

(Because I have not encountered in the build environment here is too difficult to solve the problem, some small problems can not remember, but I fear can be solved)

3. The installation is installed, and start the local server, then you can try to open the browser:

Enter the URL: http: //127.0.0.1: 8080

[My problems here]

Everything looks so beautiful, I met other people's problems encountered and solved, others do not encounter problems I encountered and also resolved, however, is unable to open the browser, always shows the connection failed, could not be opened. In seeking solutions to various pondering nearly three days later, accidentally found a response:

Enter the command:

npm install http-server

Node.js use of http-server enable local service, the browser to open. The final effect achieved is this:

 

 

 

 

Second, smart and simple application deployment contract

The above is based on the build process remix browser development environment, the next step is to write a contract by means of intelligent development platform and deployed on a private chain, step by step operation is performed to have a more profound experience of running intelligent details of the contract.

 1. Preparation of Intelligent contract

① Enter the smart contract terms:

 

 

②sol file compiled

 

 If the compiler encounters a problem at the bottom left of the page will display the error can be corrected corresponding to the point I have written.

③ obtain the corresponding parameters

After successful compilation will indicate the following:

 

 Note that the contents of the red box in the lower left, opening the menu, the following details:

 

 Click "BYTECODE" bulletin board next to put BYTECODE copy the contents, and then open a notepad to save the contents;

Click "ABI" bulletin board next to empathy save.

These two parameters will be used in the deployment of smart contract back in.

2. The deployment of intelligent contracts

Deployment of smart contract is divided into two areas: geth console, remix-ide

[Console] geth

① introduced into the creation and initialization block geth console operation set up in front of the private chain, .json file if the block containing the information has not changed you do not need initialization, you can go directly to the console:

geth --datadir ./data/00 --networkid xxxxx --port xxxx --rpc --rpcport xxxx --rpccorsdomain "*" console --allow-insecure-unlock

One by one explanation:

Phrase obvious and instructions before entering the console is different:

--networkid still the same and before, the creation of the block .json file id is what this is what

--port port number, can set their own, avoiding the fixation device can be a port number

--rpcport local rpc port number for the remix browser link will be mentioned later

--allow-insecure-unlock This is will be asked to unlock the account when the main contract to deploy in the back, set up to allow users to unlock unsafe unlock convenient back before entering the console

② successfully entered the geth console

 

③ After entering the console, first create a new account:

 

 

 

 ④ and unlock the account, because behind the remix of the operation is carried out for the account:

 

 The first parameter is in brackets unlock the object, since currently only has an account, so the account is the basic account can be used directly coinbase in place, if you have multiple accounts you want to select, then you can do the following:

Enter the command: eth.accounts displays all current accounts

Input command: personal.unlockAccount (eth.account [i], "xxxx", 1000 * 60 * 30) to unlock the first i + 1 i.e. an account password of XXXX, unlock time is 1000 * 60 * 30 ms (equivalent to about that is, 30 minutes)

 

【remix-ide】

① Select "environment" as "web3 provider"

 

 ② If the above step by step instructions to do so in accordance with the text in question here connection failure does not occur, or if the geth do not follow the above requirements to enter the console will appear the following error message:

not possible to connect to the web3 provider

(Once again remember the tips above do back again)

③ Click web3 provider will prompt box:

 

 Note that the port number is not very familiar, this is the --rpcport previously mentioned, when the parameters of the port number completed in accordance with the instructions here had the error will not enter the console, otherwise a connection failure error message will appear.

④ Click OK, if all goes well, you will find the relevant parameters on the left side of the page is automatically populated as content under geth console:

 

 Then click "Deploy" to deploy the smart contract helloworld.sol networkid corresponding to 314,590 square Ethernet network up.

⑤ If geth performed in accordance with the above operation, this will be displayed pending normal, otherwise the account will be unlocked error appears:

 

 pending indicates that the contract be resolved. What does this mean? It means that the contract has not been recognized by the entire network, not be deployed.

How to do? We know that deployment contract is implemented by way of trade, it is necessary to perform the step of mining operations, so that the contract be validated entire network. So we return to geth console, enter the command:

miner.start()

Geth found in mining, while also remix the appropriate response:

 

 Represents a successful mining contract verified, then the private chain deployed to go up.

⑥ also remember to save us in Notepad above two parameters do? BYTECODE and ABI

Enter the next geth console:

code = "BYTECODE content"

abi = ABI the contents
(code content to be double quotes, abi without, look carefully yo)

⑦ input command:

mycontract=eth.contract(abi)

contract=mycontract.new({from:eth.coinbase,data:code,gas:1000000})

⑧ contract created, but also need to deploy mining:

miner.start()

⑨ try to call intelligent contracts:

contract. .call function name (the contract content corresponding to the function parameters)

Hopefully there will be corresponding to the result, but I have not been successful, always show:

gas required exceeds allowance xxx

So if you see this article have corresponding solutions welcome guidance grateful.

Because here I was not successful, but in the Windows environment will display the corresponding steps described is not persuasive, the next article will use the truffle ganache with a way to re-try to deploy a smart contract. (This successful, do not worry ~)

over, please correct me

 

Guess you like

Origin www.cnblogs.com/shall1995/p/11618757.html