Ethereum Smart Contract related

Source: Internet
Author: User
Tags port number

Truffle is a local tool for compiling and deploying smart contracts. Testrpc is different from Geth,geth is a real ethereum environment, TESTRPC is a local use of memory simulation of an ethereum environment, for development debugging, more convenient, when the contract in the TESTRPC test passed, then deployed to Geth. So it can be said that truffle and Testrpc are two big killing device.

Install TESTRPC and Truffle separately

NPM install-g Ethereumjs-testrpc
NPM Install-g Truffle

TESTRPC starting the Local environment

Truffle in the windows of the pit (groping for several days, no one is trouble). Need to remove Truffle.js in Windows

During groping, the project is initialized with truffle init and then configured.

After truffle launched the boxes function, we can directly apply the template called Pet-shop, which has been integrated, can be directly used to develop react the web, saving time for project setup.

The command is as follows: (Pet-shop here is a box of other pets)

Truffle unbox Pet-shop

Modify Truffle-config.js after installation is complete

Module.exports = {
  //See 

Using zeppelin-solidity to simplify the development process of crypto wallet

NPM Install Zeppelin-solidity
Create a new contract file for a currency. Example: The new Guicoin.sol content under the contracts directory is as follows:
pragma solidity ^0.4.4;
Import "Zeppelin-solidity/contracts/token/erc20/standardtoken.sol";

Contract Guicoin is standardtoken {
  string public name = "Guicoin";//Currency name
  string Public symbol = "GC";//currency abbreviation
  Uint8 Public decimals = 4;//number of coins,
  uint256 public initial_supply = 200000;//The number of this currency
function guicoin () public{< c17/>totalsupply_= initial_supply;
   Balances[msg.sender] = initial_supply;//assigns a currency to the developer
  }
}

Here are some of the functions under zeppelin-solidity for later development

Contract Guicoin is Standardtoken
The above statement indicates that we inherit the Standardtoken contract and support the functions specified in the following ERC20 standards. Therefore, the following partial functions are supported
function Method
Totalsupply () Total amount of tokens issued
Balanceof (A) Query the number of tokens under a account
Transfer (A,X) Send x tokens to a account
Transferfrom (a,x) Extract x tokens from a account
Approve (a,x) Agree to a account to withdraw tokens from my account
Allowance (A, B) Query B account can withdraw from a account how many tokens

As before, the balanceof and transfer two functions are used for subsequent validation. Because the Standardtoken contract has helped us implement these functions, we don't need to write them from scratch.
To define a point example for a coin compilation: Create a new file under the Migrations directory 3_deploy_guichain.js content as follows

var encryptedtoken = Artifacts.require ('./guicoin.sol ');//reference to contract
Module.exports = function (deployer) { 
	Deployer.deploy (Encryptedtoken);
	

Execute Truffle Compile build contract

Truffle compile

Execute Truffle Migrate Deployment contract

Truffle migrate

Verify that the currency is successful and can support the transaction (truffle console enters the truffle console)

Truffle console
Let contract  (define a variable under the console)
Guicoin.deployed (). Then (instance = contract = instance)  //instantiate Guicoin as contract
Contract.balanceof (web3.eth.coinbase)//View the base of the currency, actually is the developer's currency number

Contract.balanceof (Web3.eth.accounts[1])//View the number of coins for a second user

Contract.transfer (Web3.eth.accounts[1], 800)//Turn 800 coins for the second account to detect if the send is successful.
The creation of the currency under the private chain is complete successfully.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.