LoginSignup
13
13

More than 5 years have passed since last update.

SolidityのMappingについて

Posted at

最近、Ethereumを触っていまして、contract作成用のSolidityという言語を触っています。

下記のページにSolidityの説明が詳細に載っています。
Solidity by example

読み進めてる途中、mappingというのが出てきまして、

mapping(address => Voter) public voters;

これが一体何なのか、何となく分からなかったのですが、3月半ばにEthereumのサイトが一新されまして、その中にcontract作成の例が複数のってあり、説明を見つけました。

CREATE YOUR OWN CRYPTO-CURRENCY WITH ETHEREUM

上記ページのはじめの方に、
A mapping means an associative array, where you associate addresses with balances.
と書いてあり、なるほど連想配列か、と理解。

つまり下記の例だと、

mapping (address => uint256) public balanceOf;
mapping (address => bool) public frozenAccount; 
mapping (address => mapping (address => uint256)) public allowance;
mapping (address => mapping (address => uint256)) public spentAllowance;

balanceOfはaddressを添字としたuint256型の配列、frozenAccountはaddressを添字とたboolean型配列、allowanceとspentAllowanceはaddressを添字としたuint256型の二次元配列、ということですね。

Ethereumのページのどこかにわかり易い説明が載っているのかもしれませんが、私が見つけることができたのはこの説明だけでしたので、こちらに簡単にまとめました。

ご参考になれば幸いです。

13
13
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
13
13