Taught you how to build a smart contract test environment to develop, compile, deploy, and how to invoke contract method by JS

Chain-off, designed for developers and students, Insider!

This article from the chain off the block chain Q & A community , refused reproduced without permission.
Here Insert Picture Description

learning target

Understanding smart contract

Simple environment to build

To take advantage of solidity contract to write Hello World

Contract deployment

And interactive contracts

Intelligent use of written language solidity contract

Intelligent contract on Ethereum need to use language to write solidity. Although there are other languages ​​that can be used to write intelligent contracts such as Serpent (like Python), lll (like Fortran), but to see all the intelligent public contracts are written using solidity.

Says propaganda, solidity is a language similar to Javascript, but also around the various development tools chain solidity, are using npm belong Javascript ecosystem to offer. But I think solidity quite like Java or C #. Because and Javascript different, solidity and Java or C # belong to a strongly typed (Strong Type, specify the type when you define a variable) language, also need to specify the type of return of (type) when you define the function (function), also need compile to perform. These features are not available in Javascript.

Preparing for development

This article will use the most active intelligent development framework truffle current contract basis to develop. ENS (Ethereum Name Service) is using truffle framework. Other options also embark and so on.

Like a normal website or App developers like before providing public services, developers will write for myself in the computer program (also known as the machine) or by a test network to test the effect of program execution, the test is completed, it It will be deployed to provide service on a public network. Process development block chain intelligence contracts (program) as well. In particular all the open chain calculation result is written or read operations need real money (virtual token), and based on network conditions, the operation of the chain needs to be disclosed for each short reaction time (15 seconds to several min), these wait quite a waste of valuable development time ⏳. Therefore, in the development process, we will use testrpc simulation tools needed for intelligent Ethernet Square contracts memory block chain test environment on the computer.

testrpc also contains Javascript version of Ethereum virtual machine (Ethereum Virtual Machine), so you can fully perform intelligent contracts.

In addition, the need to prepare before the development of a co-editor of the hand. I currently use Atom with solidity to develop plug-ins. In addition to supporting syntax highlighting plug solidity addition, through Solium will prompt inspection and basic grammatical mistakes, very convenient. Other editors should have a similar plug-ins to choose from.

Installation tools

Node.js must first be installed on the development machine, and then the tools needed to install using the following command:

$ npm install -g ethereumjs-testrpc truffle

liyuechun:~ yuechunli$ npm install -g ethereumjs-testrpc truffle

/usr/local/bin/testrpc -> /usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js

/usr/local/bin/truffle -> /usr/local/lib/node_modules/truffle/build/cli.bundled.js

added 1 package and updated 7 packages in 76.132s

liyuechun: ~ yuechunli $

Start Testrpc

After installation you can always use the command to start testrpc Square Ethernet test environment.

liyuechun: ~ yuechunli $ testrpc

EthereumJS TestRPC v4.1.3 (ganache-core: 1.1.3)

Available Accounts

==================

(0) 0xbbd414b340f2255dab9d923428c97f0b65d9df81

(1) 0xe9869e3cf29b6fca81762c314df229c7c4fea25e

(2) 0xc79e72362a4511b9e499d186654332c4d6f569be

(3) 0x9a6f0651907c149d4173c03927144dbbba1473d4

(4) 0x5b13a5d6788752b26dd4e338aae2e01058ee145e

(5) 0xfc7f56d942ad5260be23ecee92a344aba1b7e7d8

(6) 0xc48dc22c6bacd6ade4421ab54f25bc45c1c51142

(7) 0x3fe2b7d4141dd0a456661f77086d055cbaf3b78f

(8) 0x567979fed26ca85e9d1b4ac919c840e3fc9857e2

(9) 0xb2eafe245f098eef1c2c1f466d9a8dcd58764c62

Private Keys

==================

(0) 947ab78e91133103612ca099d60e6c38cac5bb769f7f097c82d003cf058500bd

(1) 8ffe0ba8dc53e16944a17dddd3378b5fba0379cd84df4e5237b8b46d05b8762f

(2) ffe2e04e43e4106b247407656f5233bcc3e0c49730972d0df9c1d1093375e2ef

(3) a20e453dc44c76aaca6a22efdbb605c2ed9eea64c11317e683461e11bd105ea7

(4) 4748268ff1b828868dc56d07a1b121b427e1bdede5dbb3c14ef1254d9d26b1a5

(5) f9957e68c6d20d38b81604a0509e6c4591478bc754f87d5682564073705fbb46

(6) 34e648b23c0ace6b2b0893651d87f70be8496f97ecf6b7b4607b2acc4e05c9bd

(7) d2477cedec217e3fb19a5981dafbc125ef66ccc9dc7df29301d08a24da843cf5

(8) d319f85ccd80e55b2e707e05f09662632564c297248f8b96f82ea5eeaeef0851

(9) 88c33ac9f1062b82f9e82f86a0ce307e3bd8fcf683b9751232c2f193f5bdc668

HD Wallet

==================

Mnemonic: hire custom clinic expect fury fantasy try dress source spy viable flag

Base HD Path: m/44’/60’/0’/0/{account_index}

Listening on localhost:8545

Can be automatically started after seeing testrpc established account 10 (Accounts), with each account corresponding private key (Private Key). Each account in both Ethernet 100 test coin (Ether). Pay attention to testrpc run only in memory, so each time you re-open will return to a new state.

Everything is ready, we can start building the first intelligent project contract.

create project

Open another terminal window, enter the following command to create the project:

liyuechun: Desktop yuechunli $ mkdir SmartContractDemo

liyuechun: Desktop yuechunli $ cd SmartContractDemo /

liyuechun: SmartContractDemo yuechunli $ mkdir HelloWorld

liyuechun: SmartContractDemo yuechunli $ cd HelloWorld /

liyuechun:HelloWorld yuechunli$ truffle init

Downloading project…

Project initialized.

Documentation: http://truffleframework.com/docs

Commands:

Compile: truffle compile

Migrate: truffle migrate

Test: truffle test

liyuechun: HelloWorld yuechunli $ ls

contracts migrations test truffle.js

Directory Structure:

/ Contracts: a place to store the original contract intelligent code, you can see that there have been three sol documents, we have developed HelloWorld.sol file is stored here.

/ Migrations: This function is used to deploy smart Truffle contract, a little later we will modify 2_deploy_contracts.js to deploy HelloWorld.sol.

/ Test: intelligent code testing contract on here, with the support js sol test.

truffle.js: Truffle setting document.

New contract HelloWorld

New contracts HelloWorld.sol file folder, of course, can be executed directly truffle create contract HelloWorld HelloWorld commands directly in the path below to create HelloWorld.sol.

HelloWorld.sol document reads as follows:

pragma solidity ^ 0.4.4;

contract HelloWorld {

function sayHello() returns (string) {

return ("Hello World");

}

}

explain

pragma solidity ^ 0.4.4;

The first line named solidity version currently used different versions of solidity may compile different bytecode. ^ Behalf of solidity``0.4.4 ~ 0.4.9 compatible version.

contract HelloWorld {

...

}

contract language keywords similar to other more common class. Because solidity is designed for intelligent contracts (Contact) design language, built after the declaration contract required the development of intelligent functions contract. The phrase can also be understood as a class HelloWorld extends Contract.

function sayHello() returns (string) {

return ("Hello World");

}

Structure and function is similar to other programs, but if there is an incoming parameters or return values, you need to specify the type parameters or return values ​​(type).

Compile

Now execute truffle compile command, we can HelloWorld.sol source code is compiled into Ethereum bytecode.

liyuechun: HelloWorld yuechunli $ ls

contracts migrations test truffle.js

liyuechun:HelloWorld yuechunli$ truffle compile

Compiling ./contracts/ConvertLib.sol…

Compiling ./contracts/HelloWorld.sol…

Compiling ./contracts/MetaCoin.sol…

Compiling ./contracts/Migrations.sol…

Writing artifacts to ./build/contracts

liyuechun: HelloWorld yuechunli $ ls

build contracts migrations test truffle.js

liyuechun:HelloWorld yuechunli$ cd build/

liyuechun: build yuechunli $ ls

contracts

liyuechun: build yuechunli $ cd contracts /

liyuechun: contracts yuechunli $ ls

ConvertLib.json HelloWorld.json MetaCoin.json Migrations.json

liyuechun:contracts yuechunli$ cat HelloWorld.json

{

“contract_name”: “HelloWorld”,

"Help": [

{

  "inputs": [],

  "payable": false,

  "type": "constructor"

}

],

“unlinked_binary”: “0x60606040523415600e57600080fd5b5b5b5b603680601e6000396000f30060606040525b600080fd00a165627a7a723058203ee98a767948e9bc08094df4a46ab0361f068b2a559032cf968df5bbf63e91430029”,

“networks”: {},

“schema_version”: “0.0.5”,

“updated_at”: 1505805826302

}

liyuechun: contracts yuechunli $

After successful compilation, will HelloWorld folder under the build / contracts folder below to see HelloWorld.json file.

deploy

truffle framework provides a convenient script to deploy contracts. Open migrations / 2_deploy_contracts.js files (scripts written in Javascript), the content is modified as follows:

var HelloWorld = artifacts.require(“HelloWorld”);

module.exports = function(deployer) {

deployer.deploy(HelloWorld);

};

Use artifacts.require statement to get the contract ready to deploy. Use deployer.deploy statement will be deployed to the contract block chain. Here HelloWorld is the name of the contract rather than the file name. So you can use this syntax to read any file in a .sol any one contract.

Now execute truffle migrate command:

liyuechun: HelloWorld yuechunli $ ls

build contracts migrations test truffle.js

liyuechun:HelloWorld yuechunli$ truffle migrate

Compiling ./contracts/HelloWorld.sol…

Writing artifacts to ./build/contracts

Using network ‘development’.

Running migration: 1_initial_migration.js

Deploying Migrations…

... 0x218431f16a5cadc6347449808d981887c90b3872898af7cc9dc9b3280c07c184

Migrations: 0x64e9673cf962d21642a08635e6654fb7f2ea9bcd

Saving successful migration to network…

… 0xd9ec788c106df36b8491c95a0ab02ff1e5ef22c1965c910a2576e8259a00535c

Saving artifacts…

Running migration: 2_deploy_contracts.js

Deploying HelloWorld…

... 0x17774b4914d7bc7ab2505a53c59bda6a1fce30c9839d19d735290ca9140450ea

HelloWorld: 0x471a22ffe2bddd02e82853059871067e4c07a7f4

Saving successful migration to network…

… 0xe5e2e11cf5a63ca4517221c68dadb3cae2ca42cbfed93c09c575b6d5f275fc8b

Saving artifacts…

liyuechun: HelloWorld yuechunli $

As a result the contract has been deployed to testrpc. Switch to testrpc window, you can see the testrpc reactive.

Interaction with the contract

truffle provides a command line tool, after the implementation of truffle console command, Javascript can be used to interact with the contract and just deployed.

liyuechun: HelloWorld yuechunli $ ls

build contracts migrations test truffle.js

liyuechun: HelloWorld yuechunli $ truffle console

truffle(development)> HelloWorld.deployed().then(instance => contract = instance)

TruffleContract {

constructor:

{ [Function: TruffleContract]

_static_methods:

  { setProvider: [Function: setProvider],

    new: [Function: new],

    at: [Function: at],

    deployed: [Function: deployed],

    defaults: [Function: defaults],

    hasNetwork: [Function: hasNetwork],

    isDeployed: [Function: isDeployed],

    detectNetwork: [Function: detectNetwork],

    setNetwork: [Function: setNetwork],

    resetAddress: [Function: resetAddress],

    link: [Function: link],

    clone: [Function: clone],

    addProp: [Function: addProp],

    toJSON: [Function: toJSON] },

_properties:

  { contract_name: [Object],

    abi: [Object],

    network: [Function: network],

    networks: [Function: networks],

    address: [Object],

    links: [Function: links],

    events: [Function: events],

    binary: [Function: binary],

    unlinked_binary: [Object],

    schema_version: [Function: schema_version],

    updated_at: [Function: updated_at] },

_property_values: {},

_json:

  { contract_name: 'HelloWorld',

    default_network: undefined,

    abi: [Array],

    unlinked_binary: '0x6060604052341561000f57600080fd5b5b6101488061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ef5fb05b811461003d575b600080fd5b341561004857600080fd5b6100506100c8565b60405160208082528190810183818151815260200191508051906020019080838360005b8381101561008d5780820151818401525b602001610074565b50505050905090810190601f1680156100ba5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100d061010a565b60408051908101604052600b81527f48656c6c6f20576f726c64000000000000000000000000000000000000000000602082015290505b90565b602060405190810160405260008152905600a165627a7a723058202b9d4dd8e7739264271524ea58db573fa09a0b634d1d5b78502e6dd01d76ba330029',

    networks: [Object],

    schema_version: '0.0.5',

    updated_at: 1505806918535 },

setProvider: [Function: bound setProvider],

new: [Function: bound new],

at: [Function: bound at],

deployed: [Function: bound deployed],

defaults: [Function: bound defaults],

hasNetwork: [Function: bound hasNetwork],

isDeployed: [Function: bound isDeployed],

detectNetwork: [Function: bound detectNetwork],

setNetwork: [Function: bound setNetwork],

resetAddress: [Function: bound resetAddress],

link: [Function: bound link],

clone: [Function: bound clone],

addProp: [Function: bound addProp],

toJSON: [Function: bound toJSON],

web3:

  Web3 {

    _requestManager: [Object],

    currentProvider: [Object],

    eth: [Object],

    db: [Object],

    shh: [Object],

    net: [Object],

    personal: [Object],

    bzz: [Object],

    settings: [Object],

    version: [Object],

    providers: [Object],

    _extend: [Object] },

class_defaults:

  { from: '0xbbd414b340f2255dab9d923428c97f0b65d9df81',

    gas: 4712388,

    gasPrice: 100000000000 },

currentProvider:

  HttpProvider {

    host: 'http://localhost:8545',

    timeout: 0,

    send: [Function],

    sendAsync: [Function],

    _alreadyWrapped: true },

network_id: '1505794143155' },

assistance:

[ { constant: false,

  inputs: [],

  name: 'sayHello',

  outputs: [Array],

  payable: false,

  type: 'function' } ],

contract:

Contract {

_eth:

  Eth {

    _requestManager: [Object],

    getBalance: [Object],

    getStorageAt: [Object],

    getCode: [Object],

    getBlock: [Object],

    getUncle: [Object],

    getCompilers: [Object],

    getBlockTransactionCount: [Object],

    getBlockUncleCount: [Object],

    getTransaction: [Object],

    getTransactionFromBlock: [Object],

    getTransactionReceipt: [Object],

    getTransactionCount: [Object],

    call: [Object],

    estimateGas: [Object],

    sendRawTransaction: [Object],

    signTransaction: [Object],

    sendTransaction: [Object],

    sign: [Object],

    compile: [Object],

    submitWork: [Object],

    getWork: [Object],

    coinbase: [Getter],

    getCoinbase: [Object],

    mining: [Getter],

    getMining: [Object],

    hashrate: [Getter],

    getHashrate: [Object],

    syncing: [Getter],

    getSyncing: [Object],

    gasPrice: [Getter],

    getGasPrice: [Object],

    accounts: [Getter],

    getAccounts: [Object],

    blockNumber: [Getter],

    getBlockNumber: [Object],

    protocolVersion: [Getter],

    getProtocolVersion: [Object],

    iban: [Object],

    sendIBANTransaction: [Function: bound transfer] },

transactionHash: null,

address: '0x471a22ffe2bddd02e82853059871067e4c07a7f4',

abi: [ [Object] ],

sayHello:

  { [Function: bound ]

    request: [Function: bound ],

    call: [Function: bound ],

    sendTransaction: [Function: bound ],

    estimateGas: [Function: bound ],

    getData: [Function: bound ],

    '': [Circular] },

allEvents: [Function: bound ] },

sayHello:

{ [Function]

call: [Function],

sendTransaction: [Function],

request: [Function: bound ],

estimateGas: [Function] },

sendTransaction: [Function],

send: [Function],

allEvents: [Function: bound ],

address: ‘0x471a22ffe2bddd02e82853059871067e4c07a7f4’,

transactionHash: null }

truffle(development)> contract.sayHello.call()

‘Hello World’

truffle(development)>

explain

HelloWorld.deployed().then(instance => contract = instance)

truffle console preloading the library truffle-contract, to facilitate the operation to contract the deployment block chain.

Here use HelloWorld.deployed (). Then statements to obtain Instance HelloWorld contract (example), the contract variables exist to facilitate subsequent calls.

The above is the use of Javascript ES6 + grammar, sentence can also be written as:

HelloWorld.deployed().then(instance => {

contract = instance

});

ES5 can also use the wording:

HelloWorld.deployed().then(function(instance) {

hello = instance;

});

truffle(development)> contract.sayHello.call()

‘Hello World’

Here direct call contract.sayHello () will get the same result. truffle-contract provides the use of call () to read the read-only (read only) data need not be provided so that gas. Therefore, if the operation encountered the need to write data to the block chain, we can not use the call statement.

In this way, we have written and deployed the first intelligent contracts, a contract can indeed also verified the operation.

Add a new method

We then add a echo method HelloWorld.sol in, echo method accepts a parameter input and return parameters passed.

function echo(string name) constant returns (string) {

return name;

}

The new echo method, passing a parameter name. We've also added a constant declared as echo method, this method indicates that the call does not change the state of the block chain. Thus, when this method is invoked through truffle-contract, automatically picks the call to call, no need to provide additional gas.

Since the updated contract terms, we need to re-compile a new one, will be deployed to compile the results on testrpc, and then look at the results through the implementation of truffle console.

liyuechun: HelloWorld yuechunli $ ls

build contracts migrations test truffle.js

liyuechun:HelloWorld yuechunli$ truffle compile

Compiling ./contracts/HelloWorld.sol…

Writing artifacts to ./build/contracts

liyuechun:HelloWorld yuechunli$ truffle migrate --reset

Using network ‘development’.

Running migration: 1_initial_migration.js

Replacing Migrations…

… 0x64cdc42e08a7e3f8070c46d4877ba246d95cbbccbfe1b9abd2450cfc02b48eda

Migrations: 0x42843f6a470b84e2669f19686a223c1bdefb6f4d

Saving successful migration to network…

… 0x57042b767c0f40a4f88ce855e39549010d6d5ae5f880771a45c1f7f36ea0e5b3

Saving artifacts…

Running migration: 2_deploy_contracts.js

Replacing HelloWorld…

... 0x2330e3264aae9d6be3744d8fc71d235fc6dc2934d33ff5159ae209df4cf8f12b

HelloWorld: 0xbf68789cdd6be1577339e8c739abfa1190c31b6c

Saving successful migration to network…

… 0xb4b706d7004654215067ea5954a32f0562b32724d1c646dc43b688b466b10159

Saving artifacts…

liyuechun: HelloWorld yuechunli $ truffle console

truffle(development)> let contract

undefined

truffle(development)> HelloWorld.deployed().then(instance => contract = instance)

TruffleContract {

constructor:

{ [Function: TruffleContract]

_static_methods:

  { setProvider: [Function: setProvider],

    new: [Function: new],

    at: [Function: at],

    deployed: [Function: deployed],

    defaults: [Function: defaults],

    hasNetwork: [Function: hasNetwork],

    isDeployed: [Function: isDeployed],

    detectNetwork: [Function: detectNetwork],

    setNetwork: [Function: setNetwork],

    resetAddress: [Function: resetAddress],

    link: [Function: link],

    clone: [Function: clone],

    addProp: [Function: addProp],

    toJSON: [Function: toJSON] },

_properties:

  { contract_name: [Object],

    abi: [Object],

    network: [Function: network],

    networks: [Function: networks],

    address: [Object],

    links: [Function: links],

    events: [Function: events],

    binary: [Function: binary],

    unlinked_binary: [Object],

    schema_version: [Function: schema_version],

    updated_at: [Function: updated_at] },

_property_values: {},

_json:

  { contract_name: 'HelloWorld',

    default_network: undefined,

    abi: [Array],

    unlinked_binary: '0x6060604052341561000f57600080fd5b5b61022c8061001f6000396000f300606060405263ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ef5fb05b8114610048578063f15da729146100d3575b600080fd5b341561005357600080fd5b61005b61019c565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100985780820151818401525b60200161007f565b50505050905090810190601f1680156100c55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100de57600080fd5b61005b60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506101de95505050505050565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100985780820151818401525b60200161007f565b50505050905090810190601f1680156100c55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101a46101ee565b60408051908101604052600b81527f48656c6c6f20576f726c64000000000000000000000000000000000000000000602082015290505b90565b6101e66101ee565b50805b919050565b602060405190810160405260008152905600a165627a7a723058208fec8695bd430eed53d1591d841c6e80b1a32a91caab996bb270d54425ebd7140029',

    networks: [Object],

    schema_version: '0.0.5',

    updated_at: 1505809278810 },

setProvider: [Function: bound setProvider],

new: [Function: bound new],

at: [Function: bound at],

deployed: [Function: bound deployed],

defaults: [Function: bound defaults],

hasNetwork: [Function: bound hasNetwork],

isDeployed: [Function: bound isDeployed],

detectNetwork: [Function: bound detectNetwork],

setNetwork: [Function: bound setNetwork],

resetAddress: [Function: bound resetAddress],

link: [Function: bound link],

clone: [Function: bound clone],

addProp: [Function: bound addProp],

toJSON: [Function: bound toJSON],

web3:

  Web3 {

    _requestManager: [Object],

    currentProvider: [Object],

    eth: [Object],

    db: [Object],

    shh: [Object],

    net: [Object],

    personal: [Object],

    bzz: [Object],

    settings: [Object],

    version: [Object],

    providers: [Object],

    _extend: [Object] },

class_defaults:

  { from: '0xbbd414b340f2255dab9d923428c97f0b65d9df81',

    gas: 4712388,

    gasPrice: 100000000000 },

currentProvider:

  HttpProvider {

    host: 'http://localhost:8545',

    timeout: 0,

    send: [Function],

    sendAsync: [Function],

    _alreadyWrapped: true },

network_id: '1505794143155' },

assistance:

[ { constant: false,

  inputs: [],

  name: 'sayHello',

  outputs: [Array],

  payable: false,

  type: 'function' },

{ constant: true,

  inputs: [Array],

  name: 'echo',

  outputs: [Array],

  payable: false,

  type: 'function' } ],

contract:

Contract {

_eth:

  Eth {

    _requestManager: [Object],

    getBalance: [Object],

    getStorageAt: [Object],

    getCode: [Object],

    getBlock: [Object],

    getUncle: [Object],

    getCompilers: [Object],

    getBlockTransactionCount: [Object],

    getBlockUncleCount: [Object],

    getTransaction: [Object],

    getTransactionFromBlock: [Object],

    getTransactionReceipt: [Object],

    getTransactionCount: [Object],

    call: [Object],

    estimateGas: [Object],

    sendRawTransaction: [Object],

    signTransaction: [Object],

    sendTransaction: [Object],

    sign: [Object],

    compile: [Object],

    submitWork: [Object],

    getWork: [Object],

    coinbase: [Getter],

    getCoinbase: [Object],

    mining: [Getter],

    getMining: [Object],

    hashrate: [Getter],

    getHashrate: [Object],

    syncing: [Getter],

    getSyncing: [Object],

    gasPrice: [Getter],

    getGasPrice: [Object],

    accounts: [Getter],

    getAccounts: [Object],

    blockNumber: [Getter],

    getBlockNumber: [Object],

    protocolVersion: [Getter],

    getProtocolVersion: [Object],

    iban: [Object],

    sendIBANTransaction: [Function: bound transfer] },

transactionHash: null,

address: '0xbf68789cdd6be1577339e8c739abfa1190c31b6c',

abi: [ [Object], [Object] ],

sayHello:

  { [Function: bound ]

    request: [Function: bound ],

    call: [Function: bound ],

    sendTransaction: [Function: bound ],

    estimateGas: [Function: bound ],

    getData: [Function: bound ],

    '': [Circular] },

echo:

  { [Function: bound ]

    request: [Function: bound ],

    call: [Function: bound ],

    sendTransaction: [Function: bound ],

    estimateGas: [Function: bound ],

    getData: [Function: bound ],

    string: [Circular] },

allEvents: [Function: bound ] },

sayHello:

{ [Function]

call: [Function],

sendTransaction: [Function],

request: [Function: bound ],

estimateGas: [Function] },

echo:

{ [Function]

call: [Function],

sendTransaction: [Function],

request: [Function: bound ],

estimateGas: [Function] },

sendTransaction: [Function],

send: [Function],

allEvents: [Function: bound ],

address: ‘0xbf68789cdd6be1577339e8c739abfa1190c31b6c’,

transactionHash: null }

truffle (development)> contract.echo ( "Chun micro letter: liyc1215")

'Chun micro-channel: liyc1215'

truffle(development)>

echo method does what we will enter a return. And because the statement of the constant, we do not need to directly call call () method, truffle automatically picks the call to call.

Another point to note, if this is still a truffle migrate command, we get the following information:

$ truffle migrate

Using network ‘development’.

Network up to date.

Truffle will tell you now contracts on the network are up to date, but in fact just the program in the new method has not been updated to the memory block chain. To update the program on the memory block chain deployed, migrations need to rewrite the script, but now is not the time to introduce the migration. Fortunately, we have developed a memory block chain is how to modify testrpc not matter, you can use truffle migrate --reset command to redeploy one directly on testrpc.

Guess you like

Origin blog.csdn.net/weixin_44172023/article/details/91038627