[SOLVED] Value out-of-bounds

i wanna ask why at terminal its say… value out-of-bounds (argument=“endurance”, value=100000, code=INVALID_ARGUMENT, version=abi/5.0.7)

hope someone can help me

Hi @Kaisanz,

Please provide the following details –

  1. Were you following a tutorial to build this project? If yes, which one.
  2. When is this error showing up? Upon compilation of code? Or upon transaction execution?
  3. Did you compare your code with the Github repository and see if there are any changes?
  4. Also, please paste your code here instead of a screenshot. It will be very helpful for debugging.

Thanks.

Alright wait I update the forum

I know the tutorial, you have uint8 parameter for mint function and you are trying to set value 100000 that is a value that is greater than maximum that can be represented on 8 bits (255 is the maximum on 8 bits). You’ll have to use lower values for endurance or change the function parameter to uint256.

thanks it work but after that i have problem

pragma solidity 0.8.0;

import “…/node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol”;

import “…/node_modules/@openzeppelin/contracts/access/Ownable.sol”;

contract Token is ERC721, Ownable {

struct Pet{

    uint8 damage; //0-255

    uint8 magic;

    uint256 lastMeal;      //makanan dia

    uint256 endurance;    //berapa lama dia hidup

}   

uint256 nextId = 0;

mapping( uint256 => Pet) private _tokenDetails;

constructor(string memory name, string memory symbol) ERC721(name, symbol){

}

function GetTokenDetails(uint256 tokenId)public view returns (Pet memory){

    return _tokenDetails[tokenId];

}

    

function mint(uint8 damage, uint8 magic, uint256 endurance) public onlyOwner {

    _safeMint(msg.sender, nextId);

    _tokenDetails[nextId]= Pet(damage, magic, block.timestamp, endurance); 

    nextId++;

}

function feed(uint256 tokenId) public{

    Pet storage pet =  _tokenDetails[nextId];

    require(pet.lastMeal + pet.endurance > block.timestamp);

    pet.lastMeal = block.timestamp;

}



function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override{

     Pet storage pet =  _tokenDetails[nextId];

        require(pet.lastMeal + pet.endurance > block.timestamp);     //pet masih hidup

}

}

the problem now is Error: Returned error: VM Exception while processing transaction: revert

toturial link:https://youtu.be/y519kGkAQd8

my version of that contract:

pragma solidity 0.8.5;

import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";


contract Token is ERC721, Ownable {
    struct Pet {
        uint8 damage;
        uint8 magic;
        uint32 lastMeal;
        uint32 endurance;
    }

    uint256 nextId = 0;

    mapping(uint256 => Pet) private _tokenDetails;

    constructor(string memory name, string memory symbol) ERC721(name, symbol){
        
    }

    function getTokenDetails(uint256 tokenId) public view returns (Pet memory){
        return _tokenDetails[tokenId];
    }

    function mint(uint8 damage, uint8 magic, uint32 endurance) public onlyOwner {
        _tokenDetails[nextId] = Pet(damage, magic, uint32(block.timestamp), endurance);
        _safeMint(msg.sender, nextId);
        nextId += 1;
    }

    function feed(uint256 tokenId) public {
        Pet storage pet = _tokenDetails[tokenId];
        require(pet.lastMeal + pet.endurance > block.timestamp);
        _tokenDetails[tokenId].lastMeal = uint32(block.timestamp);
    }

    function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal override {
        Pet storage pet = _tokenDetails[tokenId];
        require(pet.lastMeal + pet.endurance > uint32(block.timestamp));
    }

}


1 Like

for this can i see

const Token = artifacts.require(“Token”);

module.exports = async function (deployer) {

await deployer.deploy(Token, “NFT Game”, “NFTG”);

let tokenInstance = await Token.deployed();

await tokenInstance.mint(100, 200, 100000); //token id 0

let pet = await tokenInstance.getTokenDetails(0);

console.log(pet);

};

cuz went i try your code but got problem at 2_migration_token

const Token = artifacts.require("Token");

module.exports = async function (deployer) {
  await deployer.deploy(Token, "NTF token 2", "NTF2");
  let tokenInstance = await Token.deployed();

  await tokenInstance.mint(100, 200, 100000);
  await tokenInstance.mint(120, 140, 150000);
  let pet_0 = await tokenInstance.getTokenDetails(0);
  let pet_1 = await tokenInstance.getTokenDetails(1);
  console.log(pet_0);
  console.log(pet_1);

};

why i follow u but still have erro at TypeError: tokenInstance.getTokenDetails is not a function

and after that i try using the old coding but get error at Error: Returned error: VM Exception while processing transaction: revert

The function is there, anyway, you can skip that part that calls that function if you want.

function getTokenDetails(uint256 tokenId) public view returns (Pet memory){
    return _tokenDetails[tokenId];
}

pragma solidity 0.8.0;

import “…/node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol”;

import “…/node_modules/@openzeppelin/contracts/access/Ownable.sol”;

contract Token is ERC721, Ownable {

   struct Pet{

       uint8 damage; //0-255

       uint8 magic;

       uint256 lastMeal;      //makanan dia

       uint256 endurance;    //berapa lama dia hidup

   }   



   uint256 nextId = 0;



   mapping( uint256 => Pet) private _tokenDetails;



   constructor(string memory name, string memory symbol) ERC721(name, symbol){



}

function mint(uint8 damage, uint8 magic, uint256 endurance) public onlyOwner {

    _safeMint(msg.sender, nextId);

    _tokenDetails[nextId] = Pet(damage, magic, block.timestamp, endurance);

    nextId++;

}

function feed(uint256 tokenId) public{

    Pet storage pet =  _tokenDetails[nextId];

    require(pet.lastMeal + pet.endurance > block.timestamp);

    pet.lastMeal = block.timestamp;

}



function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override{

     Pet storage pet =  _tokenDetails[nextId];

     require(pet.lastMeal + pet.endurance > block.timestamp);     //pet masih hidup

}

}

after i delete that part error Error: Returned error: VM Exception while processing transaction: revert

its become like this

Please look on how add code in forum here: READ BEFORE POSTING - How to post code in the forum

pragma solidity 0.8.0;

   import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";

   import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

      

   contract Token is ERC721, Ownable {   

       struct Pet{

           uint8 damage; //0-255

           uint8 magic;

           uint256 lastMeal;      //makanan dia

           uint256 endurance;    //berapa lama dia hidup

       }   

   

       uint256 nextId = 0;

   

        mapping( uint256 => Pet) private _tokenDetails;

   

        constructor(string memory name, string memory symbol) ERC721(name, symbol){

    }

    function getTokenDetails(uint256 tokenId) public view returns (Pet memory){

        return _tokenDetails[tokenId];

    }

   

    function mint(uint8 damage, uint8 magic, uint256 endurance) public onlyOwner {

        _safeMint(msg.sender, nextId);

        _tokenDetails[nextId] = Pet(damage, magic, block.timestamp, endurance);

        nextId++;

    }

    function feed(uint256 tokenId) public{

        Pet storage pet =  _tokenDetails[nextId];

        require(pet.lastMeal + pet.endurance > block.timestamp);

        pet.lastMeal = block.timestamp;

    }

 

    function _beforeTokenTransfer(address from,address to,uint256 tokenId) internal override{

         Pet storage pet =  _tokenDetails[nextId];

         require(pet.lastMeal + pet.endurance > block.timestamp);     //pet masih hidup

    }

}`Preformatted text`

sorry im newbie so dont really know

like this right still blur hehe

it looks like you have to use

    function mint(uint8 damage, uint8 magic, uint256 endurance) public onlyOwner {
        _tokenDetails[nextId] = Pet(damage, magic, block.timestamp, endurance);
        _safeMint(msg.sender, nextId);
        nextId++;
    }

instead of

    function mint(uint8 damage, uint8 magic, uint256 endurance) public onlyOwner {
        _safeMint(msg.sender, nextId);
        _tokenDetails[nextId] = Pet(damage, magic, block.timestamp, endurance);
        nextId++;
    }

its work it thanks bro

1 Like