1

I am doing a udemy course and can't get the code to work even though I copied from the instructor to try and get it to work.

Error: Parsererror: expected identifier, got 'Assign' totalSupply = initialSupply;

Thanks in advance!


Here is the full code:

pragma solidity ^0.4.16;

contract Token {
mapping (address => uint256) public balanceOf;
string public name;
string public symbol;
uint8 public decimal = 18;
uint256 public totalSupply;
event Transfer(address indexed from, address indexed to, uint256 value);

function Token(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits){
 balanceOf[msg.sender
 ]= 1000;
 totalSupply = initialSupply;
 decimal=decimalUnits;
 "GD" =tokenSymbol;
 "gadget" = tokenName;
}

//Might have to check > signs
function transfer(address _to, uint256 _value){
    require(_to != 0x0);
    require(balanceOf[msg.sender] >_value);

    require(balanceOf[_to] +_value > balanceOf[_to]) ;

    balanceOf[msg.sender] -= _value;
    balanceOf[_to] += _value;
    Transfer(msg.sender, _to, _value);

}

}

contract AssetToken is admined, Token {

function AssetToken(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSymbol, decimalUnits){
totalSupply = initialSupply;
if(centralAdmin != 0){
    admin = centralAdmin;
}
else
{
    admin = msg.sender;
}
balanceOf [admin] = initialSupply;
totalSupply = initialSupply;
}}

function mintToken(address target, uint256 mintedAmount) onlyAdmin{
    balanceOf[target] += mintedAmount;
    totalSupply += mintedAmount;
    Transfer(0, this, mintedAmount);
    Transfer(this, target, mintedAmount);
}
}

function(address _to, uint256 _value){
    require(balanceOf[msg.sender] <0);
    require(balanceOf[msg.sender] <_value);

    require(balanceOf [_to] + _value < balanceOf[_to]);

    balanceOf[msg.sender] -= _value;
    balanceOf[_to] += value;
    Transfer(msg.sender, _to, _value);
}
}
}
}
1

This line:

function AssetToken(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSymbol, decimalUnits);

should probably not have a semicolon and should instead have an opening curly brace {. (And then don't forget to add a closing curly brace at the end of the function.)

EDIT

Fixed up code:

contract AssetToken is admined, Token {
    function AssetToken(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSymbol, decimalUnits) {
        totalSupply = initialSupply;
        if(centralAdmin != 0) {
            admin = centralAdmin;
        }
        else {
            admin = msg.sender;
        }
        balanceOf [admin] = initialSupply;
        totalSupply = initialSupply;
    }

    function mintToken(address target, uint256 mintedAmount) onlyAdmin {
        balanceOf[target] += mintedAmount;
        totalSupply += mintedAmount;
        Transfer(0, this, mintedAmount);
        Transfer(this, target, mintedAmount);
    }

    function(address _to, uint256 _value) {
        require(balanceOf[msg.sender] < 0);
        require(balanceOf[msg.sender] < _value);

        require(balanceOf [_to] + _value < balanceOf[_to]);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += value;
        Transfer(msg.sender, _to, _value);
    }
}
  • Thank you so much for such a quick response. Unfortunately when I add the curly braces I then get an error in the line after the closing curly bracket stating: "Parsererror: Expected pragma, import directive or contract/interface/library definition." – darknightsy Jan 15 '18 at 4:14
  • Can you edit your question to have the current full source code (properly formatted, please!)? – smarx Jan 15 '18 at 4:15
  • Also, it's helpful to say what line the error is on. – smarx Jan 15 '18 at 4:15
  • Actually, you have a ton of extra curly braces. :-) – smarx Jan 15 '18 at 4:16
1

In my opinion, you have closed your contracts (curly braces) in a wrong way. One file can contain more than one contract in it. The contracts are like classes in other programming languages eg: java. just like that, a .sol file can also contain more than one class and each class is treated as an individual contract.

point to be noted that one contract cannot be contained inside another contract (which you have done), although we can use the functionalities of other contracts interchangeably using various methods.

also you have tried to assign a lvalue to a string, which is not possible until you are trying to do something which is not visible from the posted code.

 "GD" =tokenSymbol;
 "gadget" = tokenName;

Also, there is one more error in your contract, a Fallback function cannot take arguments and it needs to be payable in order to accept ethers.

The correct code is as follows:

pragma solidity ^0.4.16;

contract Token {
mapping (address => uint256) public balanceOf;
string public name;
string public symbol;
uint8 public decimal = 18;
uint256 public totalSupply;
event Transfer(address indexed from, address indexed to, uint256 value);

function Token(uint256 initialSupply, string tokenName, string tokenSymbol, uint8 
decimalUnits){
balanceOf[msg.sender]= 1000;
totalSupply = initialSupply;
decimal=decimalUnits;
tokenSymbol="GD"; 
tokenName="gadget";
}

//Might have to check > signs
function transfer(address _to, uint256 _value){
require(_to != 0x0);
require(balanceOf[msg.sender] >_value);

require(balanceOf[_to] +_value > balanceOf[_to]) ;

balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
Transfer(msg.sender, _to, _value);

   }

}// closing contract Token

contract AssetToken is admined, Token {

function AssetToken(uint256 initialSupply, string tokenName, string tokenSymbol, 
uint8 decimalUnits, address centralAdmin) Token(0, tokenName, tokenSymbol, 
decimalUnits){
totalSupply = initialSupply;
if(centralAdmin != 0){
admin = centralAdmin;
}
else{
admin = msg.sender;
}
balanceOf [admin] = initialSupply;
totalSupply = initialSupply;
}

function mintToken(address target, uint256 mintedAmount) onlyAdmin{
balanceOf[target] += mintedAmount;
totalSupply += mintedAmount;
Transfer(0, this, mintedAmount);
Transfer(this, target, mintedAmount);
}

function() payable{

}


function makeItOneMoreFunction(address _to, uint256 _value){

require(balanceOf[msg.sender] <0);
require(balanceOf[msg.sender] <_value);

require(balanceOf [_to] + _value < balanceOf[_to]);

balanceOf[msg.sender] -= _value;
balanceOf[_to] += value;
Transfer(msg.sender, _to, _value);
}
} // closing contract AssetToken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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