
Env preparation:
Node : v8.9.0
Npm: 5.5.1
mkdir smartcontract including two files package. json、Hello.sol。
smartcontract
├── Hello.sol
└── package.json
Edit package.json:

fs module : provides an API for interacting with the file system
solc module: solidity smart contract compiler
web3: package tool provided from Ethereum, used to communicate with smart contract.
Step 1 : smart contract writing
open Hello.sol

Step 2: smart contract compile
open deploy.js

ABI: Application Binary Interface. An interface between two binary program modules; often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
Step 3: Smart Contract Deploy
$node deploy.js
compileCode:

Open a new terminal and run ganache-cil, you should see all the transactions logs here;

Arrow points to contract address: 0xbf474d24ba8b19811db5deb51137ddccbe3ff288;
Step 4:Smart Contract invoke
Writing code to call function say() for testing. Build new file called run.js

$node run.js
You should be able to see 'Hello world' in the terminal
In summary
One contract experiences four stages : contract writing -> compile-> deploy-> call
网友评论