Created
January 31, 2022 10:45
-
-
Save ZakriaJanjua/e281272efc0634a1da29cd9b223210da to your computer and use it in GitHub Desktop.
mapping and nested mapping in solidity
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.7.0 <0.9.0; | |
contract Mapping { | |
mapping(uint => Book) public books; | |
//nested mapping | |
mapping(address => mapping(uint8 => Book)) public myBooks; | |
struct Book { | |
string author; | |
string title; | |
} | |
function addBook(uint _id, string memory _author, string memory _title) public { | |
books[_id] = Book(_author, _title); | |
} | |
function addMyBook(uint8 _id, string memory _author, string memory _title) public { | |
myBooks[msg.sender][_id] = Book(_author, _title); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment