Skip to content

Instantly share code, notes, and snippets.

@gwmccubbin
Last active August 25, 2022 01:45
Show Gist options
  • Save gwmccubbin/f47c414760f7f3791f00775a6f1d2108 to your computer and use it in GitHub Desktop.
Save gwmccubbin/f47c414760f7f3791f00775a6f1d2108 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
contract MyContract {
// Mappings
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);
}
}
@hwy419
Copy link

hwy419 commented Aug 25, 2022

Found this very helpful. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment