Download Geth よりダウンロードしてインストール
実行
毎回unlockは面倒だから,2つのアカウントはpasswordファイルでunlockして起動。passwordファイルは1つづつ改行
geth --unlock 0,1 --password c:\gethdata\pass.txt --mine --minerthreads 1 --identity "sampleNode" --rpc --rpcport 8545 --rpcapi "web3,eth,net,personal" --rpccorsdomain "*" --rpcaddr "0.0.0.0" --datadir "C:\gethdata" --nodiscover --networkid 10 console 2>> C:\gethdata\geth.log
mineとかminerthreadsとか指定しているけど、省略してコンソールで、
>miner.start(1) null >eth.mining true >miner.stop() true
でもよし
personal.newAccount("test1")
eth.accounts
eth.coinbase
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(100,"ether")})
とか
var tx = {from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(100,"ether")} personal.sendTransaction(tx, "passphrase")
passphraseにはfromのパスワード
web3.fromWei(eth.getBalance(eth.accounts[1]),"ether")
personal.unlockAccount(アドレス, "パスワード", "アンロックの時間(秒)") personal.unlockAccount(アドレス)
eth.getTransaction('トランザクションID')
トランザクションが発行されて、マイニングが行われたら、確認できる。それまではnull
eth.getTransactionReceipt('トランザクションID')
eth.getBlock(ブロック番号);
eth.getTransactionFromBlock()
送金処理が完了しブロックに取り込まれると発行
eth.pendingTransactions
eth.hashrate
なんかわかるかも
debug.traceTransaction('アドレス');
こんな感じでfailedの情報が表示されていた。
{ failed: false, gas: 61484,
接続数確認
net.peerCount
ここでは関係ないです。ただのフレームワーク。後で分けます..
bootstrapとsessionはどうでもいいけど、いつもつかっているので。
meteor add twbs:bootstrap meteor add ethereum:web3 meteor add ethereum:accounts meteor add ethereum:blocks meteor add session
meteorのethereum:accounts
1番目のアカウントの名前
EthAccounts.find().fetch()[0].name
1番目のアカウントのアドレス
EthAccounts.find().fetch()[0].address
1番目のアカウントのEtherの残高
EthAccounts.find().fetch()[0].balance
meteorのethereum:blocks
最新のブロック番号
EthBlocks.latest.number
最新ブロックのハッシュ値
EthBlocks.latest.hash
最新ブロックを採掘した採掘者のアドレス
EthBlocks.latest.miner
イーサリアムの開発フレームワークです。まずはインストール
npm install -g truffle
以下のサイトを参考
参考Ethereumアプリの開発フレームワークTruffle入門
参考【イーサリアム】 SolidityとTruffleでペットショップのDappをつくる!
OpenZeppelin?ライブラリを入れて、
npm i zeppelin-solidity
truffle develop
でコンソールに入って
compile migrate
作ったコントラクトは、コンソールの中で、使える。
var tt = コントラクト.at(TutorialToken.address) tt.transfer(web3.eth.accounts[2], 10e18)
コントラクト.deployed()
とやると、ABIが見える。app.jsとかをみてると、
deployed().then
とかあるけど、truffle-contract.jsに
deployed: function()
があった。thenがいるから、Promiseなんだろうな。
import "../node_modules/zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";
にしてやる。ようはディレクトリ階層が違っていると当然駄目。
tt.transfer(web3.eth.accounts[2], 10e18)
でrevertされまくり。totalSupply_に15000とか小さい値を設定していた事が原因。
ちなみにWEBでひっかかるサンプルのソースのコンストラクタでは、totalSupplyってなっているけど、
zeppelin-solidity/contracts/token/ERC20/BasicToken?.solをみるとtotalSupply_になっているので、変わったのだろう。
追記
truffle developで
tt.transfer(web3.eth.accounts[4],8,{from:web3.eth.accounts[1],gas:500000});
これでもエラーが発生。うまくいくaccountもあり調べると
truffle(develop)> tt.balanceOf(web3.eth.accounts[1]) BigNumber { s: 1, e: 0, c: [ 5 ] }
で8 > 5になっていた。
tt.transfer(web3.eth.accounts[4],5,{from:web3.eth.accounts[1],gas:500000});
にするとうまくいき、
truffle(develop)> tt.balanceOf(web3.eth.accounts[1]) BigNumber { s: 1, e: 0, c: [ 0 ] }
となった。
token/ERC20/BasicToken?.solのfunction transferで
require(_value <= balances[msg.sender]);
となっているので、当然だった..
pragma solidity ^0.4.18; import "../node_modules/zeppelin-solidity/contracts/token/ERC20/MintableToken.sol"; contract TestCoin is MintableToken { string public name = "TEST COIN"; string public symbol = "TST"; uint8 public decimals = 18; }
としていたが、
contract TestCoin is MintableToken { string public name = "TEST COIN"; string public symbol = "TST"; uint8 public decimals = 18; uint public INITIAL_SUPPLY = 15000e18; function ArayaCoin() public { totalSupply_ = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; } }
としてみた。
setMsg1とかでtestとかをセットしてやるとエラー。"test"とすると大丈夫
function Hoge() public {
とpublicをつける
throwは使うなということらしい。
if(!owner.send(this.balance)) { throw; }
を
require(owner.send(this.balance));
にする。
require(investors[i].addr.send(investors[i].amount)) i++
はrequireの最後に;が抜けていた...
require(investors[i].addr.send(investors[i].amount)); i++
【Solidity基礎】storageとmemoryを参考にstorageとmemoryの違いを確認しながら、明示的に書けとのことなので、
Investor storage inv = investors[numInvestors++];
function getAdopters() public returns (address[16]) {
でワーニング
function getAdopters() public view returns (address[16]) {
に変更 【Ethereum】【Solidity0.4.16】viewとpure修飾子
これはtruffleでmigrateした時のエラーです。build/contracts/のjsonを消す。
to.transfer(this.balance);
を
to.transfer(address(this).balance);
に修正
sha3をkeccak256に書き換える
function () public { } function () payable public { }
どっちかにしろってこと。
intrinsic gas too lowと表示されることもあるらしいのですが、transactionに設定されているgas limitが最小値よりも小さい時に発生します。
function () public payable {
の場合、
eth.sendTransaction({to:rp.address,from:eth.accounts[0],value:web3.toWei(800,"ether")});
でコントラクトに送ると、実行されている。rpは
var rp = eth.constract(....
で設定している。
function () public {
とすると、実行されない。payableがついている関数はsendTransactionが呼ばれた時に発火するので、そりゃそうか。
eth.sendTransaction({from:rp.address,to:eth.accounts[0],value:web3.toWei(800,"ether")});
fromtoを逆にすると、これはエラーになる。コントラクトから送金したら駄目で、EOA(Externally Owned Account)からだとOK。なぜだ。
function transfer(address to, uint256 value) public { to.transfer(value); }
を作って、
rp.transfer.sendTransaction(eth.accounts[1],web3.toWei(50,"ether"),{from:eth.accounts[1],gas:500000});
で送れた。zeppelin-solidityを見ていると、ERC20Basic.solでは、
contract ERC20Basic { function totalSupply() public view returns (uint256); function balanceOf(address who) public view returns (uint256); function transfer(address to, uint256 value) public returns (bool); event Transfer(address indexed from, address indexed to, uint256 value); }
ってなっており、BasicToken?.solでtransferの実装をしているので、ないとだめなのかな。だいぶんfallbackと逸れた...
gethでタブで補完してくれるのだが、
var r4 = eth.contract(....
とかで作成しても、r4.でタブを押しても補完してくれない。
var rf = eth.contract(....
とか数値以外にすると、rf.でタブで、
rf._eth rf.adpsender rf.cntfallback rf.sender rf.abi rf.allEvents rf.constructor rf.transactionHash rf.address rf.amount rf.deposit rf.transfer
とか補完してくれる...
truffle unbox tutorialtoken
で作ったやつで、OpenZeppelinを活用してセキュアのコントラクトを書く を参考にやってみたのだが、
tt.transfer(web3.eth.accounts[3], 600e18)
した後でないと、MetaMask?でエラーがでる。
vm exception while processing transaction:revert
なぜだ...
browser-solidity
なんかlocalにコネクトができなくなった...なので、
https://remix.ethereum.org/
からダイレクトに使ってます。
web3.eth.hashrateとかどんなのがあるかみたい時に。
Web3 JavaScript app API for 0.2x.x
if (keccak256("hoge1") == keccak256("hoge2")) {
とする。
if ("hoge1" == "hoge2") {
ではなく、ハッシュ値で比較。
Solidityでcontract A Is Bとかあるんだけど、Inheritanceなので継承。以下を読んでみると、Solidity supports multiple inheritanceなので、多重継承可。
インターフェイスではなかったのですね。
例)
contract StandardToken is ERC20, BasicToken {
参考:Solidity in Depth » Contracts
truffle(develop)> var balance = new web3.BigNumber('1234567890.12345678901234567890'); undefined truffle(develop)> balance.toString() '1234567890.1234567890123456789' truffle(develop)> balance BigNumber { s: 1, e: 9, c: [ 1234567890, 12345678901234, 56789000000000 ] }
sとかeはなんなんやろ... s + eが整数の桁数ぽいが...
ブロックチェーンの基本的な仕組み
git
[Japanese] Meteorを使ってDappを作ろう
ガスと取引コスト: Gas Limit と Gas Price とは?
技術者向け Ethereum(イーサリアム)の基礎知識
【Solidity基礎】storageとmemory
【Solidity基礎】modifier修飾子について
【Solidity基礎】view、pure関数修飾子
Solidity 言語仕様 コントラクト篇
ganache
Web開発者がスマートコントラクト開発で戸惑いがちなポイント7個
Truffle: Contract.call()が返すのはPromiseなのでハマった
【Solidity基礎】型の種類
EthereumのsendTransaction時のvalidationエラー一覧
EthereumのBest Practiceが適用されたICO Crowdsale(クラウドセール)のコードを書いてみる
Ethereumテストネット上でクラウドセール(Crowdsale)を開催する