geth

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")

アンロック アンロックの時間はデフォルト300秒

personal.unlockAccount(アドレス, "パスワード", "アンロックの時間(秒)")
personal.unlockAccount(アドレス)

トランザクション確認 #送金でトランザクションIDが表示されている

eth.getTransaction('トランザクションID')

トランザクションレシート

トランザクションが発行されて、マイニングが行われたら、確認できる。それまではnull

eth.getTransactionReceipt('トランザクションID')

ブロック確認

eth.getBlock(ブロック番号);

ブロックの中身を取得

eth.getTransactionFromBlock()

ペンディングトランザクションを確認

送金処理が完了しブロックに取り込まれると発行

eth.pendingTransactions

ハッシュレート

eth.hashrate

トランザクションのトレース

なんかわかるかも

debug.traceTransaction('アドレス');

こんな感じでfailedの情報が表示されていた。

{
 failed: false,
 gas: 61484,

接続数確認

net.peerCount

meteor

ここでは関係ないです。ただのフレームワーク。後で分けます..
bootstrapとsessionはどうでもいいけど、いつもつかっているので。

meteor add twbs:bootstrap 
meteor add ethereum:web3
meteor add ethereum:accounts
meteor add ethereum:blocks
meteor add session

EthAccounts?

meteorのethereum:accounts
1番目のアカウントの名前

EthAccounts.find().fetch()[0].name

1番目のアカウントのアドレス

EthAccounts.find().fetch()[0].address

1番目のアカウントのEtherの残高

EthAccounts.find().fetch()[0].balance

EthBlocks?

meteorのethereum:blocks
最新のブロック番号

EthBlocks.latest.number

最新ブロックのハッシュ値

EthBlocks.latest.hash

最新ブロックを採掘した採掘者のアドレス

EthBlocks.latest.miner

truffle

イーサリアムの開発フレームワークです。まずはインストール

npm install -g truffle

以下のサイトを参考
参考Ethereumアプリの開発フレームワークTruffle入門
参考【イーサリアム】 SolidityとTruffleでペットショップのDappをつくる!

Browser-Solidity エラー

errored: Error encoding arguments: SyntaxError?: Unexpected token e in JSON at position 2

setMsg1とかでtestとかをセットしてやるとエラー。"test"とすると大丈夫

Warning: No visibility specified. Defaulting to "public". function Hoge() {

function Hoge() public {

とpublicをつける

Warning: "throw" is deprecated in favour of "revert()", "require()" and "assert()". throw;

throwは使うなということらしい。

if(!owner.send(this.balance)) {
  throw;
}

require(owner.send(this.balance));

にする。

ParserError?: Expected token Semicolon got 'Identifier' i++;

require(investors[i].addr.send(investors[i].amount))
i++

はrequireの最後に;が抜けていた...

require(investors[i].addr.send(investors[i].amount));
i++

Warning: Variable is declared as a storage pointer. Use an explicit "storage" keyword to silence this warning. Investor inv = investors[numInvestors++];

【Solidity基礎】storageとmemoryを参考にstorageとmemoryの違いを確認しながら、明示的に書けとのことなので、

Investor storage inv = investors[numInvestors++];

Warning: Function state mutability can be restricted to view

function getAdopters() public returns (address[16]) {

でワーニング

function getAdopters() public view returns (address[16]) {

に変更 【Ethereum】【Solidity0.4.16】viewとpure修飾子

Error: Attempting to run transaction which calls a contract function, but recipient address 0x8cdaf0cd259887258bc13a92c0a6da92698644c0 is not a contract address

これはtruffleでmigrateした時のエラーです。build/contracts/のjsonを消す。

Warning: Using contract member "balance" inherited from the address type is deprecated. Convert the contract to "address" type to access the member. to.transfer(this.balance);

to.transfer(this.balance);

to.transfer(address(this).balance);

に修正

"sha3" has been deprecated in favour of "keccak256"

sha3をkeccak256に書き換える

Function with same name and arguments defined twice.

function () public {
}
function () payable public {
}    

どっちかにしろってこと。

調査

fallback

function () public payable {

の場合、

eth.sendTransaction({to:rp.address,from:eth.accounts[0],value:web3.toWei(800,"ether")});

でコントラクトに送ると、実行されている。

function () public {

とすると、実行されない。payableがついている関数はsendTransactionが呼ばれた時に発火するので、そりゃそうか。  eth.sendTransaction({from:rp.address,to:eth.accounts[0],value:web3.toWei(800,"ether")}); これはエラーになる。コントラクトから送金したら駄目で、EOA(Externally Owned Account)からだとOK。なぜだ。

TIPS

コマンド

Ethereum Geth コンソールコマンド一覧

Browser-Solidity

browser-solidity
なんかlocalにコネクトができなくなった...なので、
https://remix.ethereum.org/
からダイレクトに使ってます。

Web3 JavaScript app API

web3.eth.hashrateとかどんなのがあるかみたい時に。
Web3 JavaScript app API for 0.2x.x

Stringの比較

if (keccak256("hoge1") == keccak256("hoge2")) {

とする。

if ("hoge1" == "hoge2") {

ではなく、ハッシュ値で比較。

リンク

ブロックチェーンの基本的な仕組み
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入門

コメント


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS