remix-ide(Browser-solidity)を使用してGethにスマート契約を導入
12366 ワード
スマート契約とは
Solidityの言語特性
remix-ide (Browser-solidity)
https://remix.ethereum.org
https://github.com/ethereum/remix-ide
https://github.com/horizon-games/remix-app/releases
npm install remix-ide -g
remix-ide
git clone https://github.com/ethereum/remix-ide.git
git clone https://github.com/ethereum/remix.git # only if you plan to link remix and remix-ide repositories and develop on it.
cd remix-ide
npm install
npm run setupremix # only if you plan to link remix and remix-ide repositories and develop on it.
npm start
remix-ideを使用してコードを編集、コンパイルする
pragma solidity 0.4.9;
contract mshkDemo {
function mshkadd(uint a) public returns (address, uint b) {
uint resutl = a+2009;
return (msg.sender, resutl);
}
}
pragma solidity ^0.4.0
うんてん
var mahkdemoContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"a","type":"uint256"}],"name":"mshkadd","outputs":[{"name":"","type":"address"},{"name":"b","type":"uint256"}],"payable":false,"type":"function","stateMutability":"nonpayable"}]);
var mahkdemo = mahkdemoContract.new(
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000c57fe5b5b60e48061001b6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063ee64a56014603a575bfe5b3415604157fe5b60556004808035906020019091905050609e565b604051808373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019250505060405180910390f35b6000600060006107d9840190503381925092505b509150915600a165627a7a723058208fbdb1b57d864dd6c64a4880c43b12fc10e102ac0ce93221135eba28c8e1c3f50029',
gas: '4700000'
}, function (e, contract){
console.log(e, contract);
if (typeof contract.address !== 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
})
remix-ideでコンパイルされた契約をGethに配備
geth javascript console
に貼り付けて実行します.成功した掘削でブロックに梱包されると、戻ります.> miner.start()
null
> null [object Object]
Contract mined!
address: 0x702f69fe301c5d959b10fea629faf71d9ec71944
transactionHash: 0x27ca30f885ec0c10e41728bad4317f12811b65284f7a63217f6fd1f78f4e6cea
> mahkdemo
{
abi: [{
constant: false,
inputs: [{...}],
name: "mshkadd",
outputs: [{...}, {...}],
payable: false,
stateMutability: "nonpayable",
type: "function"
}],
address: "0x702f69fe301c5d959b10fea629faf71d9ec71944",
transactionHash: "0x27ca30f885ec0c10e41728bad4317f12811b65284f7a63217
allEvents: function(),
mshkadd: function()
}
mshkdemo.mshkadd.call
によって呼び出され、掘削を前提とする場合:> mahkdemo.mshkadd.call(10)
["0xf94caf51cf2aa14327e7f4b500b71e19f7b20352", 2019]
> mahkdemo.mshkadd.call(20)
["0xf94caf51cf2aa14327e7f4b500b71e19f7b20352", 2029]
> mahkdemo.mshkadd.call(30)
["0xf94caf51cf2aa14327e7f4b500b71e19f7b20352", 2039]
> mahkdemo.mshkadd.call(40)
["0xf94caf51cf2aa14327e7f4b500b71e19f7b20352", 2049]