错误:无效地址(argument="address",value=undefined,code=INVALID_ARGUMENT,version=address/5.1.0)
Posted
技术标签:
【中文标题】错误:无效地址(argument="address",value=undefined,code=INVALID_ARGUMENT,version=address/5.1.0)【英文标题】:Error: invalid address (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.1.0) 【发布时间】:2021-07-28 13:26:26 【问题描述】:我在尝试使用函数部署智能合约时遇到此错误:
“错误:无效地址 (argument="address", value=undefined, code=INVALID_ARGUMENT, version=address/5.1.0) (argument="tokenAddress", value=undefined, code=INVALID_ARGUMENT, version=abi/ 5.0.7)"
这是我的代码:
const handlePresale = async (e) =>
e.preventDefault();
const web3 = await getWeb3();
const abiData = SafeHubPresaleAbi;
const contractAddress = "0x4498F943E0a13D70B28e7565CF4E33bF443e6Bf9";
const duration =
seconds: function (val)
return val;
,
minutes: function (val)
return val * this.seconds(60);
,
hours: function (val)
return val * this.minutes(60);
,
days: function (val)
return val * this.hours(24);
,
weeks: function (val)
return val * this.days(7);
,
years: function (val)
return val * this.days(365);
,
;
const latestTime = new Date().getTime();
const openingTime = latestTime + duration.minutes(1);
const closingTime = openingTime + duration.minutes(10);
const liqAddingTime = closingTime + duration.minutes(5);
let _info =
address : "0x4498F943E0a13D70B28e7565CF4E33bF443e6Bf9",
tokenPrice : web3.utils.toWei("10", "ether"),
hardCap: web3.utils.toWei("100", "ether"),
softCap: web3.utils.toWei("30", "ether"),
minInv: web3.utils.toWei("0.1", "ether"),
maxInv: web3.utils.toWei("5", "ether"),
openingTime: openingTime,
closingTime: closingTime,
;
let _uniInfo =
listingPrice: web3.utils.toWei("20", "ether"),
liqTime: liqAddingTime,
lockTime: 365,
precentLock: 25,
;
let _stringInfo =
listingName: "WER sale",
;
const preslaeContract = await new web3.eth.Contract(
abiData,
contractAddress
);
// console.log(preslaeContract.methods)
preslaeContract.methods
.createPresale(_info,_uniInfo,_stringInfo)
.call((err, result) =>
console.log(result), console.log(err);
);
Solidity 构造函数:
constructor(address _safuFactoryAddress, address _safuDevAddress) public
require(_safuFactoryAddress != address(0));
require(_safuDevAddress != address(0));
safuFactoryAddress = payable(_safuFactoryAddress);
safuDevAddress = payable(_safuDevAddress);
【问题讨论】:
请编辑您的问题并分享合约(Solidity)构造函数。 你找到答案了吗? 【参考方案1】:由于仍然没有答案,但观看次数超过 1k,如果其他人面临同样的错误,我将在这里留下一个解决方案。
您示例中的solidity 构造函数需要2 个地址类型的参数。这意味着如果您部署您的合同,您还需要提供这 2 个。
至于部署: 无论您如何部署合约,提供所有构造函数参数都应该可以解决您的问题,并且您的合约现在应该能够部署。
如果你使用 truffle,你需要调整你的 deployer .../migrations/2_deploy_contracts.js
并传递 2 个地址以满足构造函数参数。
var SafeHubPresale = artifacts.require("./SafeHubPresale.sol");
module.exports = function(deployer)
deployer.deploy(SafeHubPresale, [address1], [address2]);
;
同样适用于测试: 比方说:
var myContract = await SafeHubPresale.new(accounts[1], accounts[2], from: accounts[0], gas: 0);
【讨论】:
以上是关于错误:无效地址(argument="address",value=undefined,code=INVALID_ARGUMENT,version=address/5.1.0)的主要内容,如果未能解决你的问题,请参考以下文章
Google Cloud 错误:错误:INVALID_ARGUMENT:请求包含无效参数
云任务创建:错误:3 INVALID_ARGUMENT:请求包含无效参数
MATLAB 无效的 MEX 文件错误:缺少符号 invalid_argument