2018-01-06-steps to create and run a smart contract

Note: the following text are referenced from the great guide website:

https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05

Just enjoy yourself!

Let's begin:

1. try to install testrpc, truffle

2. create a dir, use truffle init, to get a standard dir for your contracts

3. create a contract in the contracts dir, before that run testrpc in another terminal window, we should keep testrpc running all the time

4. type truffle compile to compile your smart contract

5. go to the Migration dir, and then add a migration js file to tell truffle to deploy the smart contract on testrpc.

Note that, each contract should have one migration js file, otherwise, when you run truffle migrate --reset, you can only get the contract placed in the end of the file.

Note that you may need to configure your truffle.js file, to tell it the correct network configurations. something like this:

module.exports = {

  networks: {

  development: {

  host: "localhost",

  port: 8545,

  network_id: "*" // Match any network id

  }

}

};

6. after you deploying your contract, you can run truffle console to interact with your contract, for example, to test the state of your contract, to call the functions to see whether they work as expected. some example code are as follows:

$ truffle console

// get the deployed version of our contract

truffle(default)>var poe = ProofOfExistence1.at(ProofOfExistence1.address)

// and print its address

truffle(default)>poe.address

0x3d3bce79cccc331e9e095e8985def13651a86004

// let's register our first "document"

truffle(default)>

poe.notarize('An amazing idea')

{ tx: '0x18ac...cb1a',

receipt:

{ transactionHash: '0x18ac...cb1a',

...

},

logs: [] }

// let's now get the proof for that document

truffle(default)>poe.proofFor('An amazing idea')

0xa3287ff8d1abde95498962c4e1dd2f50a9f75bd8810bd591a64a387b93580ee7

// To check if the contract's state was correctly changed:

truffle(default)> poe.proof()

0xa3287ff8d1abde95498962c4e1dd2f50a9f75bd8810bd591a64a387b93580ee7

你可能感兴趣的:(2018-01-06-steps to create and run a smart contract)