Skip to content

Instantly share code, notes, and snippets.

@gwmccubbin
Created March 30, 2020 16:06
Show Gist options
  • Save gwmccubbin/924de210193e0d28f2190e763d6acdd9 to your computer and use it in GitHub Desktop.
Save gwmccubbin/924de210193e0d28f2190e763d6acdd9 to your computer and use it in GitHub Desktop.
pragma solidity ^0.6.0;
contract MyContract {
// Arrays
uint[] public uintArray = [1,2,3];
string[] public stringArray = ['apple', 'banana', 'carrot'];
string[] public values;
uint[][] public array2D = [ [1,2,3], [4,5,6] ];
function addValue(string memory _value) public {
values.push(_value);
}
function valueCount() public view returns(uint) {
return values.length;
}
// 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 _index, string memory _title, string memory _author) public {
books[_index] = Book(_title, _author);
}
function addMyBook(uint _index, string memory _title, string memory _author) public {
myBooks[msg.sender][_index] = Book(_title, _author);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment