本文由威-kaifa873整理发布,仅作为项目开发需求参考!飞机@sleu88
There are five reasons for joining Fosaki:
It is a global shared Ethereum matrix project, which has global popularity. Ethereum smart contract popularity ranked in the top three for consecutive months.
var greeterSource = 'contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal { string greeting; function greeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }'
编译合约代码
然后编译合约代码:
var greeterCompiled = web3.eth.compile.solidity(greeterSource)
greeterCompiled.Token.code可以看到编译好的二进制代码 greeterCompiled.Token.info.abiDefinition可以看到合约的ABI
设置希望返回的字符串
var _greeting = "Hello World!"
通过合约对象来部署合约:
var greeter = greeterContract.new(_greeting,{from:web3.eth.accounts[0], data: greeterCompiled.greeter.code, gas: 300000}, function(e, contract){
if(!e) {
if(!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
})