11

from solidity: TypeError: Member "log" not found or not visible after argument-dependent lookup in type(library console).

Im using hardhats lib "hardhat/console.sol";

I want to console.log the mapping and its members also, How can I do that ?

enter image description here

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "../Tokens/ERC1155.sol";
import "../Interface/IJACKPOT.sol";

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

import "../utils/BokkyPooBahsDateTimeContract.sol";
import "../utils/randomNumberGenerator.sol";
import "hardhat/console.sol";
import "./AkumaToken20.sol";

contract JackPot is IJACKPOT{
    using Counters for Counters.Counter;


    ///convert all Counters to UINT256

    //Helpers
    // akumacoin address and user address 
    function getAkumaCoinBalance(address userAddress) public view returns(uint256)
    {
     IERC20 token = IERC20(0x07f658C9fd773dEC2F0a9bB54f6dDDC4e2F3012D);
     return token.balanceOf(userAddress); 
    }

    function getStringLength(string memory mystring)internal pure returns(uint256){
        return bytes(mystring).length;
    }

    function getCounter()internal view returns(uint256){
        return uint256(_counter._value);
    }

    function getParticipantAddresses(uint256 counter)
    external 
    override 
    view
    returns(address[] memory)
    {
        return _jackPots[counter]._participants;
    }

    function calculateRandomWinnerFromList(address[] memory participants,uint256 counter)
    external
    override
    returns(address)
    {
        uint256 winnerIndex = random.random(participants);
        //get send list and get random number from it
        address winner = _jackPots[counter]._participants[winnerIndex]; //winners address
        //single out the winner
        _jackPots[counter]._participants[winnerIndex] = 
        _jackPots[counter]._participants[ _jackPots[counter]._participants.length - 1 ];
        //then delete that position
        _jackPots[counter]._participants.pop();
        //then return the array of rest of the participants
        return winner;
    }
    /////////////////////////////////////////////////////////
struct jackPot{
        uint256 _jackPotId;
        uint256 _startTime;
        uint256 _endTime;
        uint256 _toMint; //counts how many number of times it is going to minted and transfered
        uint256 _entryFee;
        uint256 _prizePool;
        uint256 _nftPrizeGiven; //both acting as bool
        uint256 _prizePoolGivenToAll; //bool to check if prize of either is given
        address[] _participants; 
        string _name;
    }


    //////////////////////////////////////////////////////////

    //Counter -> JackPot
    mapping(uint256=>jackPot) internal _jackPots;
    
    Counters.Counter internal _counter;

    BokkyPooBahsDateTimeContract _dateTime;
    RandomNumber random;

    uint256[] _jackPotIds;

    constructor(){
        _dateTime = new BokkyPooBahsDateTimeContract();
        random = new RandomNumber();
    }

    function createJackpot(uint256 jackPotId,uint256 startTime,uint256 endTime,uint256 entryFee ,string memory name) 
    override
    external
    {   

        require(jackPotId>=0,"JackPot Id cannot be 0");
        require(startTime>_dateTime._now(),"StartT ime should be greater than Current Time");
        require(endTime>_dateTime._now(),"End Time should be greater than Current Time");
        require(getStringLength(name)>=0,"Name Length is not valid");
        require(endTime>startTime,"Start Time cannot be greater than start Time");
        require(startTime!=endTime,"Start and End Time cannot be equal");
        //optional, Check if date is unix timestamp
        address[] memory emptyList; //givng an empty string list for participants

        _jackPots[getCounter()] = jackPot(
            jackPotId,
            startTime,
            endTime,
            0,
            entryFee,
            0,
            0,
            0,
            emptyList,
            name
        );

        console.log(_jackPots[getCounter()]._name);
        console.log(_jackPots[getCounter()]._jackPotId);
        console.log(_jackPots[getCounter()]._startTime);
        console.log(_jackPots[getCounter()]._endTime);
        console.log(_jackPots[getCounter()]._entryFee);

        console.log("Counter Func",getCounter());
        console.log("Before Counter",_counter._value);   
        _counter.increment();
        console.log("After Counter",_counter._value);
        _jackPotIds.push(jackPotId);

        emit jackPotCreatedEvent(jackPotId,name,block.timestamp);
    }
    
    function getJackpot(uint256 counter) 
    public
    view  
    returns(jackPot memory)
    {  
        console.log(_jackPots[counter]._name);
        console.log(_jackPots[counter]._jackPotId);
        console.log(_jackPots[counter]._startTime);
        console.log(_jackPots[counter]._endTime);
        console.log(_jackPots[counter]._entryFee);

        return _jackPots[counter];
    }

    function getStartAndEndTimeOfJackPot(uint256 tokenId) external override view returns (uint256,uint256)
    {
        console.log( _jackPots[tokenId]._endTime , _jackPots[tokenId]._startTime );
        return ( _jackPots[tokenId]._endTime , _jackPots[tokenId]._startTime );
    }
    //AkumaToken Address
    function insertPartcipantsInJackpot(address tokenAddress,uint256 counter,address payable participant) override external 
    {   /*
        console.log(IERC20(tokenAddress).balanceOf(address(this)));
        //checks the custom token balance
        require(IERC20(tokenAddress).balanceOf(address(this)) >= _jackPots[counter]._entryFee,
         "Not Sufficent Funds");+

        console.log("Here");
        require(_jackPots[counter]._endTime > _dateTime._now(),
        "This Participant Cannot Enter This Jackpot, Because The Event has already started");
        */
        AkumaCoin(0x07f658C9fd773dEC2F0a9bB54f6dDDC4e2F3012D).transfer(0x001286211EcDb2ED5043f50d6634d7be924eF5D9,_jackPots[counter]._entryFee);
        //deduct that amount,sent to owner account or can be done to contract itself

        _jackPots[counter]._prizePool += _jackPots[counter]._entryFee;
        //put that entry fee in that pool

        _jackPots[counter]._toMint++;

        _jackPots[counter]._participants.push(participant);
    }
    
    function getAllJackpot() //returns all jackpotIds
    external
    view 
    override 
    returns(uint256[] memory)
    {   
        return _jackPotIds;
    }

    function prizePoolDistribution(uint256 jackPotId)
    external
    payable
    override
    returns(uint256)
    {
        require(_dateTime._now() >= _jackPots[jackPotId]._endTime ,
        "Time has not passed enough for this JackPot");
        require(_dateTime.get15DaysSeconds() >= _jackPots[jackPotId]._endTime,"15 Days have not passed for this jackpot");
        //check time after endTime ,that has it been 15 days ?
        require(_jackPots[jackPotId]._nftPrizeGiven < 1, "Prize NFT Already Given to Winner");
        
        address[] memory participants = this.getParticipantAddresses(jackPotId);
        //SideNote to call another implemented external function, use this keyword
        //then make a function in which the participants list is passed
        
        address winner =  this.calculateRandomWinnerFromList(participants,jackPotId);
        //generate a single random number from the list of participants length
        //return that address and rest of the list excluding that winner
        
        IERC20(0x7EF2e0048f5bAeDe046f6BF797943daF4ED8CB47).transfer(winner,_jackPots[jackPotId]._prizePool);
        _jackPots[jackPotId]._prizePool = 0;
        //transfers prize from prize pool to winner and makes that poll 0
        _jackPots[jackPotId]._nftPrizeGiven = 1;
        //checks if given nft prize given
        emit prizeDistributedEvent(jackPotId,block.timestamp,_jackPots[jackPotId]._participants);
        return 1;
    }

    function nftPrizeDistribution(uint256 jackPotId,address to,uint256 tokenId) external override payable returns(uint256){
        require(_dateTime._now() >= _jackPots[jackPotId]._endTime ,
        "Time has not passed enough for this JackPot");
        
        require(_dateTime.get15DaysSeconds() >= _jackPots[jackPotId]._endTime,"15 Days have not passed for this jackpot");
        //check time after endTime ,that has it been 15 days ?

        require(_jackPots[jackPotId]._prizePoolGivenToAll < 1, "Prize has been distributed to all participants");
        //checks if prize has been distributed to all participants

            //goes backwards 9,8,7...0     //tomint greater than equal to 0
        for(_jackPots[jackPotId]._toMint ; _jackPots[jackPotId]._toMint >=0;){
            
            //before mint gas check
            require(gasleft()>=200,"Not much gas left,try again");
            require(_jackPots[jackPotId]._toMint>1,"all nfts have been given to participants");

            //mint, enter custom values
            ERC1155(0xDA0bab807633f07f013f94DD0E6A4F96F8742B53).
            _mint(to,tokenId,1,"");
 
            _jackPots[jackPotId]._toMint--;

            if(_jackPots[jackPotId]._toMint==0){
               _jackPots[jackPotId]._prizePoolGivenToAll=1;
               break;
            }//checks if given to all nfts
     
            //after mint gas check
            require(_jackPots[jackPotId]._toMint>1,"all nfts have been given to participants");
            require(gasleft()>=200,"Not much gas left,try again");
        }
        emit prizeDistributedEvent(jackPotId,block.timestamp,_jackPots[jackPotId]._participants);
        return 1;
    }


}
7
  • Could you show your code please ? (just a minimal example to reproduce your issue) This would greatly help to figure out where the issue is.
    – hroussille
    May 17, 2022 at 8:54
  • ethereum.stackexchange.com/users/84305/hroussille Added Image to Post. May 17, 2022 at 9:09
  • Better put the actual code instead of an image, plus it doesn't show your version and imports.
    – hroussille
    May 17, 2022 at 9:11
  • @hroussille here. May 17, 2022 at 9:32
  • You must to include all your smart contract code. It's impossible to give you a solution with only piece of code. May 17, 2022 at 15:59

1 Answer 1

17

You have this error, because console.sol doesn't accept struct type inside console.log method. You can see what types accept console.log in original smart contract code (here).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.