Home > Software design >  Error: Type contract pSDATokenSale is not implicitly convertible to expected type contract pSDA
Error: Type contract pSDATokenSale is not implicitly convertible to expected type contract pSDA

Time:02-22

Type contract pSDATokenSale is not implicitly convertible to expected type contract pSDA.

I am getting the error above ^^ at the line with tokenContract = _tokenContract;. Any suggestions as to why this is happening and how to fix it?

pragma solidity ^0.8.12;

import "./pSDAToken.sol";


contract pSDATokenSale {
    address admin;
    pSDA public tokenContract;
    uint256 public tokenPrice;
    uint256 public tokensSold;

    event Sell(address _buyer, uint256 _amount);

    function pSDAToken(pSDATokenSale _tokenContract, uint256 _tokenPrice)
        public
    {
        admin = msg.sender;
        tokenContract = _tokenContract;
        tokenPrice = _tokenPrice;
    }

CodePudding user response:

ehy you wrote wrong the type of _tokenContract inside the function pSDAToken()

you wrote _tokenContract with type pSDATokenSale, and want to save it inside tokenContract that is pSDA type

this is the correct code:

pragma solidity ^0.8.12;

import "./pSDAToken.sol";


contract pSDATokenSale {
    address admin;
    pSDA public tokenContract;
    uint256 public tokenPrice;
    uint256 public tokensSold;

    event Sell(address _buyer, uint256 _amount);

    function pSDAToken(pSDA _tokenContract, uint256 _tokenPrice)
        public
    {
        admin = msg.sender;
        tokenContract = _tokenContract;
        tokenPrice = _tokenPrice;
    }
  • Related