在 solidity 中返回 uints 的问题
Issue with returning uints in solidity
所以我开始学习 solidity 并且我想制作一个函数来计算 return 创造的硬币总数。
这是合同的重要部分
address public owner;
mapping(address => uint) public balances;
uint totalSupply;
function mint(address receiver, uint amount) public {
require(msg.sender == owner);
// balances[receiver] = balances[receiver] + amount;
totalSupply += amount;
balances[receiver] += amount;
}
function CheckTotalSupply(uint supply) public {
returns supply;
}
当我编译时出现这个错误。
ParserError: Expected primary expression.
--> subcurrency.sol:47:9:
|
47 | returns supply;
| ^^^^^^^
问题是什么?
此外,如果我使用 return,它会显示
TypeError: Different number of arguments in return statement than in returns declaration.
--> subcurrency.sol:47:9:
|
47 | return supply;
| ^^^^^^^^^^^^^
最好使用标准的 ERC20 或任何你想创建的代币。 here 是标准的 ERC20 合约。要使用标准的 ERC20 合约,您必须导入它,并且您的代币合约应该继承它。像这样:
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract YOUR_TOKEN_CONTRACT is ERC20{
constructor() ERC20(YOU_TOKEN_NAME, YOUR_TOKEN_SYMBOL){
//code here
//for example _mint(msg.sender, 100000);
}
//code here
}
标准 ERC20 合约具有 return 总供应量 totalSupply()
的功能。所以它更容易编写代币合约。
您的代码中还有语法错误!
要return一个值你必须遵循这个语法:
function CheckTotalSupply(uint supply) public retuns(uint){
return supply;// ^ this is returns with (s) at its end
//^ this is return whitout (s) at its end
}
在 retuns
中指定要 return 的变量类型,然后在 return
中 return 按照在 returns
中指定的顺序值
所以我开始学习 solidity 并且我想制作一个函数来计算 return 创造的硬币总数。
这是合同的重要部分
address public owner;
mapping(address => uint) public balances;
uint totalSupply;
function mint(address receiver, uint amount) public {
require(msg.sender == owner);
// balances[receiver] = balances[receiver] + amount;
totalSupply += amount;
balances[receiver] += amount;
}
function CheckTotalSupply(uint supply) public {
returns supply;
}
当我编译时出现这个错误。
ParserError: Expected primary expression.
--> subcurrency.sol:47:9:
|
47 | returns supply;
| ^^^^^^^
问题是什么?
此外,如果我使用 return,它会显示
TypeError: Different number of arguments in return statement than in returns declaration.
--> subcurrency.sol:47:9:
|
47 | return supply;
| ^^^^^^^^^^^^^
最好使用标准的 ERC20 或任何你想创建的代币。 here 是标准的 ERC20 合约。要使用标准的 ERC20 合约,您必须导入它,并且您的代币合约应该继承它。像这样:
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract YOUR_TOKEN_CONTRACT is ERC20{
constructor() ERC20(YOU_TOKEN_NAME, YOUR_TOKEN_SYMBOL){
//code here
//for example _mint(msg.sender, 100000);
}
//code here
}
标准 ERC20 合约具有 return 总供应量 totalSupply()
的功能。所以它更容易编写代币合约。
您的代码中还有语法错误!
要return一个值你必须遵循这个语法:
function CheckTotalSupply(uint supply) public retuns(uint){
return supply;// ^ this is returns with (s) at its end
//^ this is return whitout (s) at its end
}
在 retuns
中指定要 return 的变量类型,然后在 return
中 return 按照在 returns
中指定的顺序值