简体   繁体   English

尝试运行智能合约时出现解析器错误

[英]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.我是智能合约开发的新手,我刚刚在 ganache 上部署了我的第一个合约。

Here's the code of SimpleLearn.sol这是 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这是 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:当我尝试使用 deployed() 方法创建合约实例时,如下所示:

let newinst = await SimpleLearn.deployed()

it is returning me a parse error as follows它返回给我一个解析错误如下

在此处输入图像描述

Note: I have already deployed my smart contract to a private blockchain using ganache注意:我已经使用 ganache 将我的智能合约部署到私有区块链在此处输入图像描述 I am not able to understand what I am missing?我不明白我错过了什么? Kindly help me out !请帮帮我! Thank you !谢谢 !

I think that is because you are not in truffle development environment.我认为那是因为你不在松露开发环境中。 first make sure ganache is running.首先确保 ganache 正在运行。 in your truffle project directory在你的松露项目目录中

 truffle console

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试在松露快递盒中使用智能合约写入数据时出现无效地址错误 - Getting an Invalid Address error when trying to write data with smart contract in truffle express box 我试图测试这种流动性智能合约代码,但如果显示错误。 流动性类似于ocaml,tezos的智能合约语言。 - I am trying to test this liquidity smart contract code but if shows error. Liquidity is similar to ocaml, tezos's smart contract language. 部署实现 IUniswapV2Router02 的智能合约时出错 - Error when deploying a smart contract that implements IUniswapV2Router02 在网站上运行solidity/部署以太坊智能合约 - Run solidity/deploy ethereum smart contract on a website 向以太坊智能合约发送价值时出错 - Error sending value to Ethereum smart contract 在币安智能链中部署合约时面临错误 - Facing error on deploying contract in Binance Smart Chain 谁在智能合约交易发生时付款? - Who pays when a smart contract transaction occurs? 以太坊 - 当我们使用智能合约时 - Ethereum - When we use the smart contract 在Testnet上部署智能合约时出现未知错误,导致合约错误 - Unknown action hi in contract error while deploying smart contract on testnet 使用 Node.js 编译和部署以太坊智能合约时出错 - Getting error when compiling and deploying ethereum smart contract with Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM