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);
}
}
@prabin04
Copy link

prabin04 commented May 3, 2022

Hi Greg, Why am I facing such error when I add book. It shows this error. What I need to do about it?

transact to MyContract.addBook errored: Error encoding arguments: Error: invalid BigNumber string (argument="value", value="MyBook", code=INVALID_ARGUMENT, version=bignumber/5.5.0)

Change the first line version code with "pragma solidity >=0.4.16 <0.9.0;" .. It should work

@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