Deploy smart contracts with the truffle framework

Source: Internet
Author: User

I developed the environment for WINDOWS7, the development process encountered a lot of pits, close-up this article to the people in need.
1. Install the node. js and Atom Editor
2, install truffle framework and TESTRPC test environment: NPM install-g ethereumjs-testrpc Truffle, if the progress is stuck, then generally is the network reason (wall), need to install CNPM:NPM installed Cnpm-g --registry=https://registry.npm.taobao.org
After installation, enter: CNPM install-g ethereumjs-testrpc Truffle
3. Enter TESTRPC to start the Ethereum test environment

You can see that the TESTRPC automatically creates 10 accounts and private keys after startup, with 100 ethereum per account
4, just do not close the terminal, and then open a new terminal, enter: mkdir ABC to create a new ABC folder, and then enter: CD ABC open folder, enter: Truffle init to create a new smart contract project, after the creation of a successful folder content as shown in the figure:

The Contracts folder is used to store smart contract files in the format. Sol
The Migrations folder is used to store the deployment files, and now there is only one file
The test folder is used to store testing files
Note: After the truffle update, the created file is different from the previous one, and there is no Metacoin this demo.
5. Open Atom and open the ABC folder

Right-click on the folder contracts, select New file, enter file name: Hello.sol, write the following:

pragma solidity ^0.4.4;
 Contract HelloWorld {
  function SayHello () returns (string) {
   return ("Hello World");
 }
}

6. Click the truffle.js file to enter the following content:

module.exports={
  networks:{
    development:{
      Host: "localhost",
      port:8545,
      network_id: "*"// Match any Netword ID
    }}}

7. Click Migrations folder, right-Create new file, enter name: 2_initial_hello.js
Enter the following:

var hello =
artifacts.require ("Hello");

Module.exports
= function (deployer) {

deployer.deploy (hello);

};

8. Now open the terminal, enter: Truffle.cmd compile to compile

Why the input is truffle.cmd, other tutorials are truffle ah. Because this is a Windows system, it is not the same ~ after a successful compilation, a new build folder will be created

9. Now execute Truffle.cmd migrate for deployment

10, the contract was deployed successfully, how to interact with it. Next, in terminal input: Truffle console
Then enter: hello.deployed (). Then (instance = contract = instance)
Then type: Contract.sayHello.call ()
You can see the return of a string Hello World
That means nothing.
The calling contract was successful.

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.