Solidity 0.8.0 sonrasında msg.sender kullanmak için payable olarak tanımlamanız gerekli. Bunu öğrenmem 1 saat sürdü(evet, acemiyim dövmeyin). sizin de sürmesin diye söyledim. Örnek kod;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; contract MyContract{ address public owner; mapping(uint => string) public names; mapping(uint => Book) public books; mapping(address => mapping(uint => Book)) public myBooks; struct Book{ string title; string author; } constructor() { names[1] = "Murtaza"; names[2] = "Selami"; names[3] = "Semsettin"; names[4] = "Muhiddin"; owner = payable(msg.sender); } function addMyBook(uint _id, string memory _title, string memory _author) public { myBooks[owner][_id] = Book(_title, _author); } } |
