I'm facing a little issue here, that's the mintTo function from contract for NFT. Which I require the sender to send a value with >= 0.1 Ether:
pragma solidity ^0.5.0;
import "./TradeableERC721Token.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
/**
* @title Creature
* Creature - a contract for my non-fungible creatures.
*/
contract Creatures is TradeableERC721Token {
constructor(address _proxyRegistryAddress) TradeableERC721Token("Creatures", "CRE", _proxyRegistryAddress) public { }
function baseTokenURI() public view returns (string memory) {
return "https://metadata-link.com/api/tokens/";
}
}
pragma solidity ^0.5.0;
import 'openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol';
import 'openzeppelin-solidity/contracts/ownership/Ownable.sol';
import './Strings.sol';
contract TradeableERC721Token is ERC721Full, Ownable {
using Strings for string;
address proxyRegistryAddress;
uint256 private _currentTokenId = 0;
constructor(string memory _name, string memory _symbol, address _proxyRegistryAddress) ERC721Full(_name, _symbol) public {
proxyRegistryAddress = _proxyRegistryAddress;
}
/**
* @dev Mints a token to an address with a tokenURI.
* @param _to address of the future owner of the token
*/
function mintTo(address _to) public payable {
require(msg.value >= 0.1 ether);
address contractOwner = owner();
address(uint160(contractOwner)).transfer(msg.value);
uint256 newTokenId = _getNextTokenId();
_mint(_to, newTokenId);
_incrementTokenId();
}
/**
* @dev calculates the next token ID based on value of _currentTokenId
* @return uint256 for the next token ID
*/
function _getNextTokenId() private view returns (uint256) {
return _currentTokenId.add(1);
}
/**
* @dev increments the value of _currentTokenId
*/
function _incrementTokenId() private {
_currentTokenId++;
}
function baseTokenURI() public view returns (string memory) {
return "";
}
function tokenURI(uint256 _tokenId) external view returns (string memory) {
return Strings.strConcat(
baseTokenURI(),
Strings.uint2str(_tokenId)
);
}
/**
* Override isApprovedForAll to whitelist user's OpenSea proxy accounts to enable gas-less listings.
*/
function isApprovedForAll(
address owner,
address operator
)
public
view
returns (bool)
{
// Whitelist OpenSea proxy contract for easy trading.
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (address(proxyRegistry.proxies(owner)) == operator) {
return true;
}
return super.isApprovedForAll(owner, operator);
}
}
And Then from the client I use [email protected] to call mintTo function:
const web3 = window.web3;
const nftContract = new web3.eth.Contract(NFT_ABI, NFT_CONTRACT_ADDRESS, { gasLimit: "1000000" });
const minterAccount = await web3.eth.getAccounts();
const minter = minterAccount[0];
const result = await nftContract.methods.mintTo(minter).send({
from: minter,
value: web3.utils.toWei("0.1", "ether"),
gas: "25000",
})
.on('error', (err) => {
if (err) {
console.log(err);
}
});
Then, I get this error:
Error: "Transaction ran out of gas. Please provide more gas:
{
"blockHash": "0x9b477437e6fef51a85f0700099d4b765b199bc412dcbd912daacdfc3b1337140",
"blockNumber": 6207136,
"contractAddress": null,
"cumulativeGasUsed": 139877,
"from": "0x34b8d058df685de17c64b46248d4794ff87bb458",
"gasUsed": 21678,
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": "0x5b40cde4bde153fef88ba435cf18d7433b4113f8",
"transactionHash": "0xe9af511d933eca45d633799eada763950fee7d622c7f5b49601058fc96ed8ca8",
"transactionIndex": 4,
"events": {}
}"
I've changed send options to:
const result = await nftContract.methods.mintTo(minter).send({
from: minter,
value: web3.utils.toWei("0.1", "ether"),
gasLimit: "25000",
})
.on('error', (err) => {
if (err) {
console.log(err);
}
});
// And
const result = await nftContract.methods.mintTo(minter).send({
from: minter,
value: web3.utils.toWei("0.1", "ether"),
gas: 25000,
})
.on('error', (err) => {
if (err) {
console.log(err);
}
});
Also got the same error, I did my search but didn't figured out where is the issue from. Thanks for Help.
address(uint160(contractOwner))
whencontractOwner
is already an address type???address(uint160())
to be able to change it to payable account and then can receive the value