You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报错‘Type is not Callable’,Solidity ERC20合约代码问题求助

解决Solidity中‘Type is not Callable’错误

你的错误出在_mint函数的第二个参数写法上:

500000000(10**uint256(decimals()))

Solidity会将500000000识别为一个可调用的函数/合约,但数字类型本身不支持调用操作,因此触发了‘Type is not Callable’错误。你需要用**乘法运算符***来计算总供应量,而不是直接用括号包裹。

修正后的完整代码:

contract MentalHealthCoin is ERC20, Ownable, ReentrancyGuard {

    constructor() ERC20("Mental Health Coin", "MHC") {
        _mint(msg.sender, uint256(500000000) * (10 ** uint256(decimals()))); 
    }
}

补充说明:

  • decimals()是ERC20标准的默认函数,返回值为18,所以这里计算的是5亿枚带有18个小数位的代币。
  • 显式将500000000转换为uint256类型,可以避免不同整数类型之间隐式转换的警告,让代码更严谨。

内容的提问来源于stack exchange,提问作者Steve Harrow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 13:20:50