Solidity - Convert override method to payable with OpenZeppelin - solidity

I'm implementing the ERC721 Contract but i need the to add the payable keyword to safeTransferFrom but im getting this error :
The ERC721 has by default the payable keyword but open zeppelin hasn't.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;
import "#openzeppelin/contracts#4.3.2/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts#4.3.2/access/Ownable.sol";
import "#openzeppelin/contracts#4.3.2/utils/Counters.sol";
contract MyToken is ERC721, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() ERC721("MyToken", "MTK") {}
function safeMint(address to) public onlyOwner {
_safeMint(to, _tokenIdCounter.current());
_tokenIdCounter.increment();
}
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes memory _data
) public payable override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: transfer caller is not owner nor approved");
_safeTransfer(from, to, tokenId, _data);
}
}

Related

convert uint to string is possible now in solidity?

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
contract GoTekERC721 is ERC721, Ownable {
constructor() ERC721("Go NFT", "GoN") {}
//Owner to Phone
mapping(address => uint256[]) public phones;
//change
// Phone to Balance
mapping(uint256 => uint256) public balance;
function register(uint256 phone, uint256 Balance) public {
_mint(msg.sender, phone);
phones[msg.sender].push(phone);
balance[phone] = Balance;
}
function details(address owner) public view returns(string memory) {
uint256[] memory ownerPhones = phones[owner];
mapping(uint256 => uint256) storage userBalances;
for (uint256 i = 0; i < ownerPhones.length; i++) {
uint256 phone = ownerPhones[i];
userBalances[phone] = balance[phone];
}
return userBalances;
}
}
in solidity 0.8.9 it gets error.i don't understand what can i do to convert my mapping to string and get o/p like {"phone":"Balance","phone":"Balance"} ...thanks in adanced

Withdraw functions reverts

I'm practicing with smart contracts and still new to them. I have a instance of a contract that i'm practicing making calls too. I can get the deposit function to work when calling it from my contract but cannot get the withdraw function to work. It keeps reverting.
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
import "hardhat/console.sol";
interface Matic {
function deposit() external payable;
function withdraw(uint wad) external;
function balanceOf(address _customerAddress) external view returns(uint256);
}
contract Funds {
Matic public depositFunds;
address public owner;
constructor(address _depositFundsAddress) {
owner = msg.sender;
depositFunds = Matic(_depositFundsAddress);
}
// Fallback is called when DepositFunds sends Ether to this contract.
receive() external payable {
payable(owner).transfer(address(this).balance);
}
function deposits() external payable {
depositFunds.deposit{value: msg.value}();
}
function withDras(uint wad) external {
depositFunds.withdraw(wad);
}
function getBalance(address _owner) external view returns (uint256) {
return depositFunds.balanceOf(_owner);
}
}
here is the contract instance
/**
*Submitted for verification at polygonscan.com on 2021-06-09
*/
// https://firebird.finance DeFi multi-chain yield farms deployer & DEXs aggregator.
// Copyright (C) 2015, 2016, 2017 Dapphub
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.4.18;
contract WMATIC {
string public name = "Wrapped Matic";
string public symbol = "WMATIC";
uint8 public decimals = 18;
event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
event Deposit(address indexed dst, uint wad);
event Withdrawal(address indexed src, uint wad);
mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;
function() public payable {
deposit();
}
function deposit() public payable {
balanceOf[msg.sender] += msg.value;
Deposit(msg.sender, msg.value);
}
function withdraw(uint wad) public {
require(balanceOf[msg.sender] >= wad);
balanceOf[msg.sender] -= wad;
msg.sender.transfer(wad);
Withdrawal(msg.sender, wad);
}
function totalSupply() public view returns (uint) {
return this.balance;
}
function approve(address guy, uint wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
Approval(msg.sender, guy, wad);
return true;
}
function transfer(address dst, uint wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}
function transferFrom(address src, address dst, uint wad)
public
returns (bool)
{
require(balanceOf[src] >= wad);
if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
require(allowance[src][msg.sender] >= wad);
allowance[src][msg.sender] -= wad;
}
balanceOf[src] -= wad;
balanceOf[dst] += wad;
Transfer(src, dst, wad);
return true;
}
}
I'm not sure exactly what it is i'm doing wrong. on the instance itself the withdraw function works fine but on my contract it keeps reverting

Metadata is not showing on opensea

i am trying to develop a nft mint daap. i deploy the erc 721 contract on bsc test net(0x5542bD28FD0D8c22D4AC7D51E62735Ac32d32374) The mint function is working but the metadata is not showing on opensea test net. for metadata and image i am using pinata, here is the link for metadata
https://gateway.pinata.cloud/ipfs/Qmcchbbm2R6CdiwsYbcoLPcY7PSi7yska9HzDCvK977mMU.
the steps i am following: deploy the token, enable public mint , setting the tokenUri.
code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
contract Minter is ERC721, Ownable{
string private baseTokenURI;
uint256 public mintPrice;
uint256 public totalSupply;
uint256 public maxSupply;
uint256 public maxPerWallet;
bool public isPublicMintEnabled;
address public withdrawWallet;
mapping (address=> uint256) public walletMints;
constructor() payable ERC721("NFTTutorial", "NFT") {
mintPrice= 1 ether;
totalSupply = 0;
maxSupply=14400;
maxPerWallet= 25;
withdrawWallet=0x658385eb2Abf80C76DEeF0d99491d41Fd7B638ff;
}
function setIspublicMintEnable( bool isPublicMintEnabled_) external onlyOwner{
isPublicMintEnabled= isPublicMintEnabled_;
}
function mint(uint256 quantity_) public payable{
require(isPublicMintEnabled,"minting not enabled");
//require(msg.value== quantity_* mintPrice, " wrong mint value");
require(totalSupply+quantity_<= maxSupply,"sold out");
require(walletMints[msg.sender]+ quantity_<= maxPerWallet);
for (uint256 i=0; i <quantity_; i++){
uint256 newTokenId=totalSupply+1;
totalSupply++;
walletMints[msg.sender] = walletMints[msg.sender] + quantity_;
_safeMint(msg.sender, newTokenId);
}
}
/// #dev Returns an URI for a given token ID
function _baseURI() internal view virtual override returns (string memory) {
return baseTokenURI;
}
/// #dev Sets the base token URI prefix.
function setBaseTokenURI(string memory _baseTokenURI) public {
baseTokenURI = _baseTokenURI;
}
function withdraw(address payable _to, uint _amount) public {
_to.transfer(_amount);
}
}

I'm getting an error, a declaration error but its pointing to something in quotes which i don't understand

the error I 'm getting reads
DeclarationError: Undeclared identifier.
--> SharedWallet.sol:17:17:
|
17 | require(isOwner() || allowance[msg.sender] >= _amount, "You are not allowed!");
| ^^^^^^^
pragma solidity ^0.8.6;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
contract Allowance is Ownable {
mapping(address => uint256) public allowance;
function addAllowance(address _who, uint256 _amount) public onlyOwner {
allowance[_who] = _amount;
}
modifier ownerOrAllowed(uint256 _amount) {
require(
isOwner() || allowance[msg.sender] >= _amount,
"You are not allowed!"
);
_;
}
function reduceAllowance(address _who, uint256 _amount)
internal
ownerOrAllowed(_amount)
{
allowance[_who] -= _amount;
}
}
contract SharedWallet is Allowance {
uint256 public balanceReceived;
function sendEther() public payable {
balanceReceived += msg.value;
}
function isOwner() internal view returns (bool) {
return owner() == msg.sender;
}
function withdrawMoney(address payable _to, uint256 _amount)
public
ownerOrAllowed(_amount)
{
require(
_amount <= address(this).balance,
"not enough funds in contract"
);
if (!isOwner()) {
reduceAllowance(msg.sender, _amount);
}
_to.transfer(_amount);
}
fallback() external payable {}
}
pragma solidity ^0.8.6;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
contract Allowance is Ownable {
mapping(address => uint256) public allowance;
// This will fix compile error, or, need use inheritance to prevent duplicate code.
function isOwner() internal view returns (bool) {
return owner() == msg.sender;
}
function addAllowance(address _who, uint256 _amount) public onlyOwner {
allowance[_who] = _amount;
}
modifier ownerOrAllowed(uint256 _amount) {
require(
isOwner() || allowance[msg.sender] >= _amount,
"You are not allowed!"
);
_;
}
function reduceAllowance(address _who, uint256 _amount)
internal
ownerOrAllowed(_amount)
{
allowance[_who] -= _amount;
}
}
contract SharedWallet is Allowance {
uint256 public balanceReceived;
function sendEther() public payable {
balanceReceived += msg.value;
}
function isOwner() internal view returns (bool) {
return owner() == msg.sender;
}
function withdrawMoney(address payable _to, uint256 _amount)
public
ownerOrAllowed(_amount)
{
require(
_amount <= address(this).balance,
"not enough funds in contract"
);
if (!isOwner()) {
reduceAllowance(msg.sender, _amount);
}
_to.transfer(_amount);
}
fallback() external payable {}
}

Call token function in my service contract

I want to charge a token value to perform a function within my contract.
I created the token in the mist, did the deploy on the private network and everything is running.
my code :
contract my_contract{
function my_function() public {
do_something;
// token other contract below
token.transferFrom(msg_sender, to_address, amount);
}
}
How exactly do I do this?
How do I instantiate a token in my contract?
Include the interface for the contract you want to call in your client contract and pass in the contract address when you deploy.
Example:
pragma solidity ^0.4.18;
contract ERC20 {
function allowance(address owner, address spender) public view returns (uint256);
function transferFrom(address from, address to, uint256 value) public returns (bool);
function approve(address spender, uint256 value) public returns (bool);
function totalSupply() public view returns (uint256);
function balanceOf(address who) public view returns (uint256);
function transfer(address to, uint256 value) public returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
contract my_contract {
ERC20 _token;
function my_contract(address tokenAddress) public {
_token = ERC20(tokenAddress);
}
function my_function(address to, uint amount) public {
//do_something
_token.transferFrom(msg.sender, to, amount);
}
}