LoginSignup
7
7

More than 5 years have passed since last update.

Ethereumまとめメモ①

Last updated at Posted at 2015-11-29

Gasについて
参考
https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions

  • Gas
    contractを動かすために必要な量の単位(etherとは異なる)

  • GasPrice
    その時々で変化するgas価格
    例)
    gasprice= 0.001etherの時
    10000gasが必要なら
    0.001*10000=10etherを送金する必要がある

contractに必要なgasの量は
"web3.eth.estimateGas"
でわかる
(実際に実行はされないが、必要なgas量を算出する関数)

  • GasLimit

    • contractのaddressに送信できるGas量の限界値
    • contractの発行者が決めて良い。

GasLimitが必要な理由
  - contractにバグがありループが発生してしまう場合、それを止められなくなる。しかし、Gasが無くなるまでしかプログラムが動かないという制約を作ることで、無限ループなどでもgasがなくなれば実行が止まってくれる。送れるGasに限界量を設定するのはそのためである。
  - ちなみに、gasが切れてしまった場合、ブロックチェーン上では、すべての処理はロールバックされ元の状態と変化しないで記録される。

  • 結局contractに必要なetherの量は

(必要なgas量) × (その時のgasPrice)

で算出

Contract info (metadata)

参考
https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions

source = "contract test {
   /// @notice Will multiply `a` by 7.
   function multiply(uint a) returns(uint d) {
       return a * 7;
   }
}"
contract = eth.compile.solidity(source).test
MyContract = eth.contract(contract.info.abiDefinition)
contenthash = admin.saveInfo(contract.info, "~/dapps/shared/contracts/test/info.json")
MyContract.new({from: primary, data: contract.code}, function(error, contract){
  if(!error && contract.address) {
    admin.register(primary, contract.address, contenthash)
    // put it up on your favourite oldworld site:
    admin.registerUrl(contentHash, "http://dapphub.com/test/info.json")
  }
});
  • contentHash
    デプロイしたContractの情報(mete data)を含むinfo.jsonファイルのハッシュ値。
     これを登録する(admin.reister)

  • contentUrlを登録する

    • Urlは他の人が見れるサイト。info.jsonをアップロードしておく。
    • admin.registerUrlでそのUrlを登録する

疑問

  • なぜわざわざ情報を登録するのか?jsonをアップロードとかめんどくさいしdecentralizedと言えない。ブロックチェーンで完結しないのか?

参考サイト(上記)にこのような文言があった。

Note that if we use content addressed storage system like swarm the second step is unnecessary, since the contenthash is (deterministically translates to) the unique address of the content itself.

つまり、Swarmなどの分散データベースが実装されれば、contractにきちんと一意性のあるcontentHash値が得られるようになるが、いまはまだ実装できていないので、それまでは一意性が保てない。なので、どこかにmeta dataをアップロードしておかないと、そのcontractが信頼できるかわからない。metadataからハッシュ計算でcontentHashが得られるので、それと一致すれば良い。
 なのでcontentUrlは単にファイルが見れる場所であればどこでもよい(はず)

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7