when i want to deploy this contract in REMIX IDE i get this error:
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
Internal JSON-RPC error.
{
"code": -32000,
"message": "gas required exceeds allowance (20058647)"
}
this is my contract:
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
import "#openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "#openzeppelin/contracts/access/Ownable.sol";
contract KINGs300 is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
uint256 public cost = 0.5 ether;
uint256 public maxSupply = 300;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI
)
ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
mint(msg.sender, 300);
}
function _baseURI() internal view override virtual returns (string memory) {
return baseURI;
}
function mint(address _to, uint256 _mintAmount) public payable {
uint256 supply = totalSupply();
require(_mintAmount > 0);
require(supply + _mintAmount <= maxSupply);
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(_to, supply + i);
}
}
function walletOfOwner(address _owner) public view returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId) public view override virtual returns (string memory)
{
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI,tokenId.toString(),baseExtension))
: "";
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
}
i want to mint a collection that has 300 NFTs in it
You can't mint 300 NFTs at once because of gas Limit of blocks, check this link for the limit of ethereum
https://ethereum.org/en/developers/docs/gas/
Block limit of 30 million gas for ethereum.
Try minting less NFTs like 100 NFTs per transaction and you must send 3 tranasction for minting 300 NFTs.
Related
I am practising this tutorial in Remix IDE - https://www.youtube.com/watch?v=_aXumgdpnPU
I saw in the Chainlink documentation that their Randomness VRF code has been changed since the development of the video.
I started replacing the parts and trying to deploy the class via Remix but it gives an error which I am not sure how to fix.
Would you be able to check what I have as code and I'll send a screenshot of the error?
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;
import "#chainlink/contracts/src/v0.8/ConfirmedOwner.sol";
import "#chainlink/contracts/src/v0.8/VRFV2WrapperConsumerBase.sol";
contract Lottery is
VRFV2WrapperConsumerBase,
ConfirmedOwner
{
address public owner;
address payable[] public players;
uint public lotteryId;
mapping (uint => address payable) public lotteryHistory;
event RequestSent(uint256 requestId, uint32 numWords);
event RequestFulfilled(
uint256 requestId,
uint256[] randomWords,
uint256 payment
);
struct RequestStatus {
uint256 paid; // amount paid in link
bool fulfilled; // whether the request has been successfully fulfilled
uint256[] randomWords;
}
mapping(uint256 => RequestStatus)
public s_requests; /* requestId --> requestStatus */
// past requests Id.
uint256[] public requestIds;
uint256 public lastRequestId;
// Depends on the number of requested values that you want sent to the
// fulfillRandomWords() function. Test and adjust
// this limit based on the network that you select, the size of the request,
// and the processing of the callback request in the fulfillRandomWords()
// function.
uint32 callbackGasLimit = 100000;
// The default is 3, but you can set this higher.
uint16 requestConfirmations = 3;
// For this example, retrieve 2 random values in one request.
// Cannot exceed VRFV2Wrapper.getConfig().maxNumWords.
uint32 numWords = 2;
// Address LINK - hardcoded for Goerli
address linkAddress = 0x326C977E6efc84E512bB9C30f76E30c160eD06FB;
// address WRAPPER - hardcoded for Goerli
address wrapperAddress = 0x708701a1DfF4f478de54383E49a627eD4852C816;
constructor()
ConfirmedOwner(msg.sender)
VRFV2WrapperConsumerBase(linkAddress, wrapperAddress)
{
owner = msg.sender;
lotteryId = 1;
}
function requestRandomWords()
external
onlyOwner
returns (uint256 requestId)
{
requestId = requestRandomness(
callbackGasLimit,
requestConfirmations,
numWords
);
s_requests[requestId] = RequestStatus({
paid: VRF_V2_WRAPPER.calculateRequestPrice(callbackGasLimit),
randomWords: new uint256[](0),
fulfilled: false
});
requestIds.push(requestId);
lastRequestId = requestId;
emit RequestSent(requestId, numWords);
return requestId;
}
function fulfillRandomWords(
uint256 _requestId,
uint256[] memory _randomWords
) internal override {
require(s_requests[_requestId].paid > 0, "request not found");
s_requests[_requestId].fulfilled = true;
s_requests[_requestId].randomWords = _randomWords;
emit RequestFulfilled(
_requestId,
_randomWords,
s_requests[_requestId].paid
);
payWinner();
}
function getRequestStatus(
uint256 _requestId
)
external
view
returns (uint256 paid, bool fulfilled, uint256[] memory randomWords)
{
require(s_requests[_requestId].paid > 0, "request not found");
RequestStatus memory request = s_requests[_requestId];
return (request.paid, request.fulfilled, request.randomWords);
}
/**
* Allow withdraw of Link tokens from the contract
*/
function withdrawLink() public onlyOwner {
LinkTokenInterface link = LinkTokenInterface(linkAddress);
require(
link.transfer(msg.sender, link.balanceOf(address(this))),
"Unable to transfer"
);
}
function getWinnerByLottery(uint lottery) public view returns (address payable) {
return lotteryHistory[lottery];
}
function getBalance() public view returns (uint) {
return address(this).balance;
}
function getPlayers() public view returns (address payable[] memory) {
return players;
}
function enter() public payable {
require(msg.value > .01 ether);
// address of player entering lottery
players.push(payable(msg.sender));
}
//function getRandomNumber() public view returns (uint) {
//return uint(keccak256(abi.encodePacked(owner, block.timestamp)));
//}
function pickWinner() public onlyowner {
requestRandomWords;
}
function payWinner() public {
uint index = lastRequestId % players.length;
players[index].transfer(address(this).balance);
lotteryHistory[lotteryId] = players[index];
lotteryId++;
// reset the state of the contract
players = new address payable[](0);
}
modifier onlyowner() {
require(msg.sender == owner);
_;
}
}
enter image description here
learning solidity and curious how i can limit the minting of my NFT to only 2 per wallet address. Trying to prevent people from minting more then 2 tokens i add Maxfreemint and is working but to set max per wallet is not working please if you can provide me code solution because i try lot of solution but is not working.
pragma solidity >=0.8.9 <0.9.0;
import 'erc721a/contracts/extensions/ERC721AQueryable.sol';
import '#openzeppelin/contracts/access/Ownable.sol';
import '#openzeppelin/contracts/utils/cryptography/MerkleProof.sol';
import '#openzeppelin/contracts/security/ReentrancyGuard.sol';
contract DD is ERC721AQueryable, Ownable, ReentrancyGuard {
using Strings for uint256;
string public baseURI = '';
string public uriSuffix = '.json';
uint256 public cost;
uint256 public maxSupply;
uint256 public maxFreeMint = 4;
uint256 public maxMintAmountPerWallet = 2;
mapping(address => uint256) private _freeWalletMints;
bool public paused = true;
constructor(
string memory _tokenName,
string memory _tokenSymbol,
uint256 _cost,
uint256 _maxSupply
) ERC721A(_tokenName, _tokenSymbol) {
setCost(_cost);
maxSupply = _maxSupply;
}
modifier mintCompliance(uint256 _mintAmount) {
require(_mintAmount > 0, 'Invalid mint amount!');
require(totalSupply() + _mintAmount <= maxSupply, 'Max supply exceeded!');
_;
}
function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount){
if(msg.sender != owner()){
require(!paused, 'The contract is paused!');
require(_freeWalletMints[_msgSender()] + _mintAmount <= 2, 'You have already minted');
if (totalSupply()+_mintAmount > maxFreeMint){
require(msg.value >= cost * _mintAmount, "Insufficient funds!");
}
}
_safeMint(_msgSender(), _mintAmount);
}
function _startTokenId() internal view virtual override returns (uint256) {
return 1;
}
function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) {
require(_exists(_tokenId), 'ERC721Metadata: URI query for nonexistent token');
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, _tokenId.toString(), uriSuffix))
: '';
}
function setCost(uint256 _cost) public onlyOwner {
cost = _cost;
}
function setBaseURI(string memory _url) public onlyOwner {
baseURI = _url;
}
function setUriSuffix(string memory _uriSuffix) public onlyOwner {
uriSuffix = _uriSuffix;
}
function setPaused(bool _state) public onlyOwner {
paused = _state;
}
function withdraw() public onlyOwner nonReentrant {
(bool os, ) = payable(owner()).call{value: address(this).balance}('');
require(os);
}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
}
U am trying to implement liquidity pools with Solidity, and had written two functions : addLiquidity() and withdraw() for it. However, the withdraw function doesn't seem to work with Remix when I try to withdraw large sums (like 0.001 ether), but works with sums like 150000 wei or something.
It doesn't seem to be an issue with Remix's IDE (i read somehere it has a problem working with large numbers), because even when I pass the 149999998499999985165 wei in double quotes (e.g. "149999998499999985165") the same error appears.
The error states: "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted { "originalError": { "code": 3, "data": "0x4e487b710000000000000000000000000000000000000000000000000000000000000011", "message": "execution reverted" } }"
Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface linkStandardToken {
function transferFrom(address _from, address _to, uint256 _value) external returns (bool) ;
function balanceOf(address _owner) external returns (uint256) ;
function transfer(address to, uint tokens) external returns (bool success);
}
contract Uniswap
{
using SafeMath for uint256;
uint public totalLiquidity;
uint public balance;
address public owner;
address public tokenAddress = 0xaFF4481D10270F50f203E0763e2597776068CBc5; // REPLACE WITH ACTUAL TOKEN
linkStandardToken token;
bool public poolInit = false;
uint public protocolFees = 30; //in basis points i.e. divide by 10,000
uint public tempTokenPrice = 0;
mapping(address => uint) public liquidityBalances;
constructor()
{
owner = msg.sender;
token = linkStandardToken(tokenAddress);
}
function init(uint _tokenAmount) public payable
{
require(totalLiquidity == 0, "Already initialized");
require(_tokenAmount > 0, "Token amount must be > 0");
require(msg.value > 0, "Eth amount must be > 0");
totalLiquidity = totalLiquidity.add(_tokenAmount);
balance = balance.add(msg.value);
poolInit = true;
require(token.transferFrom(msg.sender, address(this), _tokenAmount), "Can't transfer tokens to contract");
setTokenToEthPrice();
}
fallback() payable external{}
receive() payable external{}
// _amount - input token amount, X - input token reserve, Y- output token reserve
function _swap(uint _amount, uint X , uint Y) public view returns (uint)
{
// code omitted
}
function swapEthToToken(/*uint _inputEthAmount*/) public payable
{
// code omitted
}
function swapTokenToEth(uint _tokenAmount) public payable
{
// code omitted
}
function setTokenToEthPrice() public // set to internal later
{
tempTokenPrice = _swap(1, balance , token.balanceOf(address(this))) ;
}
function addLiquidity(uint maxTokens) payable public returns (uint)
{
require(msg.value > 0, "msg.val <= 0");
require(totalLiquidity > 0, "totalLiquidity <= 0");
uint tokensBalance = getTokenBalance(address(this));
uint tokensToAdd = msg.value.mul(tokensBalance)/balance;
require(tokensToAdd <= maxTokens , "tokensToAdd > maxTokens");
balance= balance.add(msg.value);
uint mintedLiquidity = msg.value.mul(totalLiquidity)/balance;
liquidityBalances[msg.sender] = liquidityBalances[msg.sender].add(mintedLiquidity);
totalLiquidity = totalLiquidity.add(mintedLiquidity);
require(linkStandardToken(
0xaFF4481D10270F50f203E0763e2597776068CBc5)
.transferFrom(msg.sender, address(this), tokensToAdd));
return mintedLiquidity;
}
function withdraw9(uint256 amount, uint minimumEth, uint minimumTokens) public
{
require(liquidityBalances[msg.sender] >= amount, "Liquidity Balance of msg send < amount");
require(totalLiquidity > 0, "totalLiquidity <= 0");
uint tokenBalance = getTokenBalance(address(this));
uint temp = amount.mul(totalLiquidity);
uint etherToTransfer = temp.div(balance);
uint temp1 = amount.mul(totalLiquidity);
uint tokensToTransfer = temp1.div(tokenBalance);
require(minimumEth < etherToTransfer, "minimumEth >= etherToTransfer");
require(minimumTokens < tokensToTransfer, "minimumTokens >= tokensToTransfer");
balance = balance - etherToTransfer;
totalLiquidity = totalLiquidity.sub(amount);
liquidityBalances[msg.sender] = liquidityBalances[msg.sender].sub(amount);
address payable addr = payable(msg.sender);
addr.transfer(etherToTransfer);
require(linkStandardToken(
0xaFF4481D10270F50f203E0763e2597776068CBc5)
.transfer(msg.sender, tokensToTransfer), "Token transfer unsuccesful");
}
}
library SafeMath {
....// code emitted for compactness
}
As i can see in the last line of widthdraw9 function you use .transfer in order to send ether to some contract. I guess this contract have some code in receive function, so .transfer is not your choose. This function has a gas limitation and any code in receive can break it. If i correctly saw the problem then you should use .call function with enough amount of gas. More about these functions.
The "Gas estimation errored" message doesn't necessarily mean that the problem is with the amount of gas given, just that it hit some error while estimating the amount of gas needed.
The originalError.data has "0x4e487b71...". Looking up those high order 4 bytes on 4byte.directory shows that it's the signature for Panic(uint256), and the code in the low order bytes is "...00011" so the error code is 0x11 (17 decimal). The Solidity doc lists these codes, indicating:
0x11: If an arithmetic operation results in underflow or overflow outside of an unchecked { ... } block.
In the code, balance is not declared in uint etherToTransfer = temp.div(balance). If it's a state variable, could it be 0? Or is there a missing uint256 balance = liquidityBalances[msg.sender]?
I'm trying to implement PatrickAlpha NFT implementation Github. When I followed readme instructions, collectibles are minted correctly. But If I tried to change anything in the code , it gives me error like this.
Compiling contracts...
Solc version: 0.6.6
Optimizer: Enabled Runs: 200
EVM Version: Istanbul
CompilerError: solc returned the following errors:
/Users/batuhansesli/.brownie/packages/smartcontractkit/chainlink-brownie-contracts#1.0.2/contracts/src/v0.6/VRFConsumerBase.sol:2:1: ParserError: Source file requires different compiler version (current compiler is 0.6.6+commit.6c089d02.Darwin.appleclang - note that nightly builds are considered to be strictly less than the released version
pragma solidity 0.6.0;
^--------------------^
For debug, I tried to change only ERC721 constructor parameters, but error occured again.
Original Code:
pragma solidity 0.6.6;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract AdvancedCollectible is ERC721, VRFConsumerBase {
uint256 public tokenCounter;
enum Breed{PUG, SHIBA_INU, ST_BERNARD}
// add other things
mapping(bytes32 => address) public requestIdToSender;
mapping(bytes32 => string) public requestIdToTokenURI;
mapping(uint256 => Breed) public tokenIdToBreed;
mapping(bytes32 => uint256) public requestIdToTokenId;
event requestedCollectible(bytes32 indexed requestId);
bytes32 internal keyHash;
uint256 internal fee;
constructor(address _VRFCoordinator, address _LinkToken, bytes32 _keyhash)
public
VRFConsumerBase(_VRFCoordinator, _LinkToken)
ERC721("Dogie", "DOG")
{
tokenCounter = 0;
keyHash = _keyhash;
fee = 0.1 * 10 ** 18;
}
function createCollectible(string memory tokenURI, uint256 userProvidedSeed)
public returns (bytes32){
bytes32 requestId = requestRandomness(keyHash, fee, userProvidedSeed);
requestIdToSender[requestId] = msg.sender;
requestIdToTokenURI[requestId] = tokenURI;
emit requestedCollectible(requestId);
}
function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override {
address dogOwner = requestIdToSender[requestId];
string memory tokenURI = requestIdToTokenURI[requestId];
uint256 newItemId = tokenCounter;
_safeMint(dogOwner, newItemId);
_setTokenURI(newItemId, tokenURI);
Breed breed = Breed(randomNumber % 3);
tokenIdToBreed[newItemId] = breed;
requestIdToTokenId[requestId] = newItemId;
tokenCounter = tokenCounter + 1;
}
function setTokenURI(uint256 tokenId, string memory _tokenURI) public {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_setTokenURI(tokenId, _tokenURI);
}
}
My Code :
pragma solidity 0.6.6;
import "#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "#chainlink/contracts/src/v0.6/VRFConsumerBase.sol";
contract FootballerCollectible is ERC721, VRFConsumerBase {
bytes32 internal keyHash;
uint256 public fee;
uint256 public tokenCounter;
enum Player{MBAPPE, NEYMAR, MESSI, RONALDO}
mapping (bytes32 => address) public requestIdToSender;
mapping (bytes32 => string) public requestIdToTokenURI;
mapping (uint256 => Player) public tokenIdToPlayer;
event requestedCollectible(bytes32 indexed requestId);
constructor(address _VRFCoordinator, address _LinkToken, bytes32 _keyhash) public
VRFConsumer(_VRFCoordinator, _LinkToken)
ERC721("Footballer", "FTC")
{
keyHash = _keyhash;
fee = 0.1 * 10 ** 18;
tokenCounter = 0;
}
function createCollectible(uint256 userProvidedSeed, string memory tokenURI)
public returns (bytes32) {
bytes32 requestId = requestRandomness(keyHash, fee, userProvidedSeed);
requestIdToSender[requestId] = msg.sender;
requestIdToTokenURI[requestId] = tokenURI;
emit requestedCollectible(requestId);
}
function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override{
address cardOwner = requestIdToSender[requestId];
string memory tokenURI = requestIdToTokenURI[requestId];
uint256 newItemId = tokenCounter;
_safeMint(cardOwner, newItemId);
_setTokenURI(newItemId, tokenURI);
Player player = Player(randomNumber % 4);
tokenIdToPlayer[newItemId] = player;
requestIdToTokenId[requestId] = newItemId;
tokenCounter = tokenCounter + 1;
}
function setTokenURI(uint256 tokenId, string memory _tokenURI) public {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
"ERC721: transfer caller is not owner nor approved"
);
_setTokenURI(tokenId, _tokenURI);
}
}
Hi :) In the Error message that you received
Blockquote ParserError: Source file requires different compiler version (current compiler is 0.6.6+commit.6c089d02.Darwin.appleclang - note that nightly builds are considered to be strictly less than the released version
pragma solidity 0.6.0;
it says that you are trying to compile your contract with a different version of pragma solidity. The smart contract in question is:
[https://github.com/smartcontractkit/chainlink-brownie-contracts/blob/main/contracts/src/v0.6/VRFConsumerBase.sol]
which is using
pragma solidity ^0.6.0;
You are specifying to use version 0.6.6 in your contract which is later than the selected compiler. To get around this, you can either drop down to ^0.6.0 or you can change your pragma to
pragma solidity ^0.6.0;
For more information, you can read this ticket
after reading many post i can't found the issues about this Smart contract who compile but it think i miss something about the inheritance and the Abstract contract.
This is the SC :
// solium-disable linebreak-style
pragma solidity >=0.4.21 <0.6.0;
import "../node_modules/#openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/#openzeppelin/contracts/math/SafeMath.sol";
/**
* #title Ownable
* #dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address payable public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* #dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor (Ownable) public {
owner = msg.sender;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* #dev Allows the current owner to transfer control of the contract to a newOwner.
* #param newOwner The address to transfer ownership to.
*/
function transferOwnership(address payable newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract Sample is Ownable {
event NewResource (uint resourceId, string name , uint quality);
uint qualityUnits = 16;
uint qualityModulo = qualityUnits;
uint cooldownTime = 1 days;
struct Resource {
string name;
uint quality;
uint32 rarity;
uint256 cooldownTime;
uint16 stockGain;
uint16 stockLoss;
uint32 readyTime;
uint256 extractionTime;
uint256 extractionId;
uint256 magnetiteId;
uint256 hematiteId;
uint256 class;
uint256 sediments;
uint qualityUnits;
}
//mapping address and apply stocks
mapping (uint => address) public resourceToOwner;
mapping (address => uint) ownerResourceGain;
Resource[] public resources;
/// #dev function to crack the resource stacks
function _createResource (string memory _name , uint _quality) internal {
uint id = resources.push(Resource(_name,_quality ,1 , uint256( now + cooldownTime), 0 , 0, 0,
0, 0, 0, 0, 0, 0, 16) )+1;
resourceToOwner[id] = msg.sender;
ownerResourceGain[msg.sender]++;
emit NewResource(id, _name , _quality);
}
//function to generate rand stats for resources
function _generateRandomQuality(string memory _str ) private view returns (uint) {
uint rand = uint(keccak256(abi.encode(_str)));
return rand % qualityModulo;
}
//function to generate the resource stacks
function createResourceStack(string memory _name) public {
require(ownerResourceGain[msg.sender] ==0);
uint randomQuality = _generateRandomQuality(_name);
randomQuality = randomQuality - randomQuality % 100;
_createResource(_name, randomQuality);
}
}
contract CoreRefined is Sample {
//address public newContractAddress;
function getResourcesStats(uint256 _id)
external
view
returns (
bool isRefiningInProcess,
bool isReady,
uint256 cooldownTime,
//uint256 nextActionAt,
uint256 extractionTime,
uint256 extractionId,
uint256 magnetiteId,
uint256 hematiteId,
uint256 class,
uint256 sediments
)
{
Resource storage stats = resources[_id];
isRefiningInProcess = (stats.quality != 0);
isReady = (stats.cooldownTime <= block.number);
cooldownTime = uint256(stats.cooldownTime);
extractionTime = uint256(stats.extractionTime);
extractionId = uint256(stats.extractionId);
magnetiteId = uint256(stats.magnetiteId);
hematiteId = uint256(stats.hematiteId);
class = uint256(stats.class);
sediments = stats.sediments;
}
}
/// #title RefiningInterface for resource modification called refining
/// #dev Refining function inside for improving stats of resources.
contract RefiningInterface is Sample {
function refining(uint256 _id) external view returns (
bool isRefiningInProcess,
bool isReady,
uint256 cooldownTime,
uint256 nextActionsAt,
uint256 extractionTime,
uint256 extractionId,
uint256 magnetiteId,
uint256 hematiteId,
uint256 class,
uint256 sediments
);
}
contract ResourceRefined is Sample , CoreRefined {
ResourceRefined CoreRefinedContract;
modifier onlyOwnerOf(uint _resourceId) {
require(msg.sender == resourceToOwner[_resourceId]);
_;
}
function SetAnotherContractAddress (address _address) external onlyOwner {
CoreRefinedContract
= ResourceRefined(_address);
}
function triggerCooldown (Resource storage _resource ) internal {
_resource.readyTime = uint32(now+cooldownTime);
}
function _isReady ( Resource storage _resource ) internal view returns (bool) {
return (_resource.readyTime <= now);
}
function refinedAndMultiply( uint _resourceId, uint _targetQuality, string memory _types) internal onlyOwnerOf(_resourceId) {
Resource storage myResource = resources[_resourceId];
require(_isReady(myResource));
_targetQuality % qualityModulo;
uint newQuality = (myResource.quality + _targetQuality) / 2;
if(keccak256(abi.encode((_types))) == keccak256(abi.encode("Resources"))) {
newQuality = newQuality - newQuality % 100 + 99;
}
_createResource("NoName", newQuality);
triggerCooldown(myResource);
}
function refineOnInterface(uint256 _resourceId, uint256 _idResources ) public {
uint256 materialUsed;
(,,,,,,,,materialUsed) = CoreRefinedContract.getResourcesStats(_idResources);
refinedAndMultiply(_resourceId,materialUsed,"Resources");
}
}
contract ResourceHelper is ResourceRefined {
//cost ether for rarityUp fee
uint rarityForFee = 0.001 ether;
//modify rarity !=not LEVEL
modifier aboveCostLevel (uint _rarity ,uint _resourceId){
require(resources[_resourceId].rarity >= _rarity);
_;
}
//function to withdraw FIX ISSUE
/*function withdraw() external onlyOwner {
owner.transfer(this).balance;
}*/
//rarityfee for resources improvements
function setRarityFee(uint _fee) external onlyOwner {
rarityForFee = _fee;
}
//Rarity improvement function
/// #dev this function is set by using RefinedResource.sol contract in order to gain better resources
function rarityUp(uint _resourceId) external payable {
require(msg.value == rarityForFee);
resources[_resourceId].rarity++;
}
//change the name of resources
function changeName(uint _resourceId, string calldata _Newname) external aboveCostLevel(2, _resourceId) onlyOwnerOf (_resourceId){
resources[_resourceId].name = _Newname;
}
//change the qualityUnits
function changeQualityUnits(uint _resourceId, uint _newQualityUnits) external aboveCostLevel(2, _resourceId) onlyOwnerOf (_resourceId) {
resources[_resourceId].qualityUnits = _newQualityUnits;
}
//grabe the resources ! array of it.
function getTheResourceToOwner( address _owner) external view returns (uint[] memory) {
uint[] memory result = new uint[](ownerResourceGain[_owner]);
uint counter = 0;
//loop
for (uint i = 0; i < resources.length; i++) {
if (resourceToOwner[i] == _owner){
result[counter] = i;
counter++;
}
}
return result;
}
}
contract ResourceUp is ResourceHelper {
uint randNonce = 0;
uint resourceUpProba = 70;
/*function randMod(uint _modulus) internal returns(uint) {
randNonce++;
return uint(keccak256( (abi.encodePacked(now, msg.sender,randNonce))) % uint(_modulus));
}*/
function setUp(uint _resourceId, uint _targetId) external onlyOwnerOf(_resourceId) {
Resource storage myResource = resources[_resourceId];
Resource storage anotherResource = resources[_targetId];
uint rand = 100;
if (rand <= resourceUpProba) {
myResource.stockGain++;
myResource.rarity++;
anotherResource.stockLoss++;
refinedAndMultiply(_resourceId, anotherResource.quality, "resource");
} else {
myResource.stockLoss++;
anotherResource.stockGain++;
triggerCooldown(myResource);
}
}
}
contract Harvest is ResourceUp, ERC721 {
using SafeMath for uint256;
mapping (uint => address) resourceApproval;
function balanceOf(address _owner) public view returns (uint256 _balance) {
return ownerResourceGain[_owner];
}
function ownerOf(uint256 _tokenId) public view returns (address _owner) {
return resourceToOwner[_tokenId];
}
function _transfer(address _from, address _to, uint256 _tokenId) private {
ownerResourceGain[_to] = ownerResourceGain[_to].add(1);
ownerResourceGain[msg.sender] = ownerResourceGain[msg.sender].sub(1);
resourceToOwner[_tokenId] = _to;
_transfer(_from, _to, _tokenId);
}
function transferTo(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
transferTo(_to, _tokenId);
}
function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
resourceApproval[_tokenId] = _to;
emit Approval(msg.sender, _to, _tokenId);
}
function harvest(uint256 _tokenId) public {
require(resourceApproval[_tokenId] == msg.sender);
address owner = ownerOf(_tokenId);
_transfer(owner, msg.sender, _tokenId);
}
}
My depoy js file :
const Harvest = artifacts.require("Harvest");
module.exports = function(deployer) {
deployer.deploy(Harvest)
};
The output of the truffle migrate
* Import abstractions into the '.sol' file that uses them instead of deploying them separately.
* Contracts that inherit an abstraction must implement all its method signatures exactly.
* A contract that only implements part of an inherited abstraction is also considered abstract.
verions :
Truffle v5.1.9 (core: 5.1.9)
Solidity v0.5.16 (solc-js)
Node v10.16.3
Web3.js v1.2.1
Thank you for your support.
The problem is with Ownable constructor
constructor (Ownable) public {
owner = msg.sender;
}
It is defined in a way that it will receive one parameter of type Ownable.
To fix the error define it without any input parameter:
constructor() public {
owner = msg.sender;
}