Search code examples
blockchainethereumsoliditysmartcontractstruffle

Parser error when trying to run a smart contract


I'm very new to smart contract development , and I had just deployed my first contract on ganache.

Here's the code of SimpleLearn.sol

contract SimpleLearn
{
    address public payer;
    address public thirdParty;
    address public receiver;
    uint public amt;
    uint senderBal;
    uint remamount;
constructor (address _payer, uint amount, address _receiver) // constructor is invoked only once for entire 
// contract. mostly thats why invoked by thirdParty
{
payer = _payer;
receiver = _receiver;
amt = amount;
thirdParty = msg.sender;
remamount = amount;
}
mapping (address=>uint) public balances;
function deposit(uint transferm) public returns (uint)   
{
require (msg.sender == payer, "Sender must be payer");
require (transferm< remamount, "Amount to transfer should be lesser than remaining amount");
remamount = remamount - transferm;
balances[thirdParty] += transferm;
return remamount;
//return msg.sender.balance;
}
}

This is the code for 2_deploy_contract.js


module.exports = function(deployer) {
  deployer.deploy(SimpleLearn,'0x21DB98979bc3a42D58648cC22c47C11610f2E094',50,'0x62F49aE035648325320454cC8B3934F3c8c36A77');
};

when I am trying to create an instance of the contract using deployed() method as follows:

let newinst = await SimpleLearn.deployed()

it is returning me a parse error as follows

enter image description here

Note : I have already deployed my smart contract to a private blockchain using ganache enter image description here I am not able to understand what I am missing ? Kindly help me out ! Thank you !


Solution

  • I think that is because you are not in truffle development environment. first make sure ganache is running. in your truffle project directory

     truffle console
    

    enter image description here