Last active
April 28, 2020 08:43
-
-
Save andrejrakic/6f8b516c8c1e1f9ad29367ce40c99b72 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.6+commit.6c089d02.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.0; | |
contract Mappings { | |
// Mappings are data structure like dictionary in C# or hash tables in C++ | |
// O(1) | |
// mapping(key => value) myMapping; | |
// One can make nested mappings as well | |
// Mappings are like databases for blockchain and they are very useful | |
mapping(uint => string) public names; | |
mapping(uint => Book) public books; | |
mapping(address => mapping(uint => Book)) public myBooks; | |
struct Book { | |
string title; | |
string author; | |
} | |
constructor() public { | |
names[1] = "Adam"; | |
names[2] = "Bruce"; | |
names[3] = "Carl"; | |
} | |
function addBook(uint _id, string memory _title, string memory _author) public { | |
books[_id] = Book(_title, _author); | |
} | |
function addMyBook(uint _id, string memory _title, string memory _author) public { | |
myBooks[msg.sender][_id] = Book(_title, _author); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://ropsten.etherscan.io/address/0x1172fe29e1aeef398ddc5c399a7eea8797802b29#code