0

I'm having problems with compiling this controller smart contract. It's throwing error at line 18:
address payable tokenSource = {tokenAddress};

Any idea what went wrong?

Thank you, Valerie.

// SPDX-License-Identifier: MIT pragma solidity ^ 0.8.0;

interface IToken { function totalSupply() external view returns(uint256); function balanceOf(address account) external view returns(uint256); function transferFrom(address sender, address recipient, uint256 amount) external returns(bool);

}

contract TestController{ event TokenPurchased(address indexed _owner, uint256 _amount, uint256 _bnb);

IToken Token;

bool public is_preselling;
address payable owner;
address payable tokenSource = {tokenAddress};
address payable fundreceiver;
uint256 soldTokens;
uint256 receivedFunds;

constructor(IToken _tokenAddress)  {
    Token = _tokenAddress;
    owner = payable(msg.sender);
    fundreceiver = owner;
    is_preselling = true;
}

modifier onlyOwner() {
    require(msg.sender == owner, "invalid owner");
    _;
}

//buy tokens
function sale(uint256 _amount) public payable returns(bool)  {
    require(is_preselling, "pre selling is over.");
    Token.transferFrom(tokenSource, msg.sender, _amount);
    fundreceiver.transfer(msg.value);
    soldTokens += _amount;
    receivedFunds += msg.value;
    emit TokenPurchased(msg.sender, _amount, msg.value);
    return true;
}

function getTokenSupply() public view returns(uint256){
    return Token.totalSupply();
}

function getTokenbalance(address _address) public view returns(uint256){
    return Token.balanceOf(_address);
}

function totalSoldTokens() public view returns(uint256){
    return soldTokens;
}
function totalReceivedFunds() public view returns(uint256){
    return receivedFunds;
}

function getbalance()  public onlyOwner {
    owner.transfer(address(this).balance);
}


function SetReceiver(address payable _fund) public onlyOwner {
    fundreceiver = _fund;
}


function SetPreSellingStatus() public onlyOwner {
    if (is_preselling) {
        is_preselling = false;
    } else {
        is_preselling = true;
    }
}

}

0

1 Answer 1

0

You are getting this error because tokenAddress is not defined.

  • If you want to assign token address to tokenSource so you can assign in constructor.

Try to run below given code may it will solve your issue.

// SPDX-License-Identifier: MIT 
pragma solidity ^0.8.0;

interface IToken { function totalSupply() external view returns(uint256); function balanceOf(address account) external view returns(uint256); function transferFrom(address sender, address recipient, uint256 amount) external returns(bool);

}

contract TestController{ 

event TokenPurchased(address indexed _owner, uint256 _amount, uint256 _bnb);

IToken Token;

bool public is_preselling;
address payable owner;
address payable tokenSource;
address payable fundreceiver;
uint256 soldTokens;
uint256 receivedFunds;

constructor(IToken _tokenAddress)  {
    tokenSource=payable(address(_tokenAddress));
    Token = _tokenAddress;
    owner = payable(msg.sender);
    fundreceiver = owner;
    is_preselling = true;
}

modifier onlyOwner() {
    require(msg.sender == owner, "invalid owner");
    _;
}

//buy tokens
function sale(uint256 _amount) public payable returns(bool)  {
    require(is_preselling, "pre selling is over.");
    Token.transferFrom(tokenSource, msg.sender, _amount);
    fundreceiver.transfer(msg.value);
    soldTokens += _amount;
    receivedFunds += msg.value;
    emit TokenPurchased(msg.sender, _amount, msg.value);
    return true;
}

function getTokenSupply() public view returns(uint256){
    return Token.totalSupply();
}

function getTokenbalance(address _address) public view returns(uint256){
    return Token.balanceOf(_address);
}

function totalSoldTokens() public view returns(uint256){
    return soldTokens;
}
function totalReceivedFunds() public view returns(uint256){
    return receivedFunds;
}

function getbalance()  public onlyOwner {
    owner.transfer(address(this).balance);
}


function SetReceiver(address payable _fund) public onlyOwner {
    fundreceiver = _fund;
}


function SetPreSellingStatus() public onlyOwner {
    if (is_preselling) {
        is_preselling = false;
    } else {
        is_preselling = true;
    }
}
}


0

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.