Simple smart contract in ethereum remix - the contract is deprecated. Use "constructor(...) { ... }"

trying test some simple smart contract but don’t know I have error Can anybody tell me where I have a mistake?
I want to test this code but this error stops me.

I’m testing this tutorial: https://programtheblockchain.com/posts/2018/02/02/writing-a-token-sale-contract/

pragma solidity ^0.4.21;

interface IERC20Token {
function balanceOf(address owner) public returns (uint256);
function transfer(address to, uint256 amount) public returns (bool);
function decimals() public returns (uint256);
}

contract TokenSale {
IERC20Token public tokenContract = 
IERC20Token(0x12740510086c7062d5131BFe7C680c8b5D728c7f);     // the token being sold
uint256 public price = 1000000000000000;             // the price, in wei, per token
address owner;

uint256 public tokensSold;

event Sold(address buyer, uint256 amount);

function TokenSale(IERC20Token _tokenContract, uint256 _price) public {
    owner = msg.sender;
    tokenContract = _tokenContract;
    price = _price;
}

1 Like

Hey, welcome!
Ohhh, these are warnings, not errors. Before 0.4.22, always define a function that has the same name with its contract name to do some initial configurations, but sometimes developers will write typo that leads to bugs, so in 0.4.22 and later versions, expect to use a constructor keyword to create an anonymous function to do this.

BTW, current solidity compile version is 0.8.2, so maybe you should read some newer tutorials.

1 Like