Uncaught (in promise) Error: invalid address
Uncaught (in promise) Error: invalid address
如何在调用智能合约函数时修复此错误?
Uncaught (in promise) Error: invalid address (argument="address", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=address/5.0.5) (argument="index", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=abi/5.0.7)
这是我的代码:
enter: async function() {
App.contracts["MyContract"].deployed().then(async(instance) =>{
var a = web3.eth.getAccounts();
let ticketsForPlayers = await instance.getTicketsForPlayers({from: App.account});
console.log(ticketsForPlayers);
});
}
问题
错误表明您没有正确设置 address
属性,这可能是您的 solidity
实现的问题,与 javascript 无关片段,如评论中所述,您可以在相关网站上询问它,但上面的片段有一些点可能对您有所帮助。
您在 enter
方法中混合了两种不同的实现来处理明显不正确并导致问题的承诺。
积分
使用 async/await
和 try/catch
块。有关 MDN 文档的更多信息:
enter: async function () {
try {
const instance = await App.contracts["MyContract"].deployed()
const properNameForVariable = web3.eth.getAccounts();
const ticketsForPlayers = await instance.getTicketsForPlayers({from: App.account})
console.log(ticketsForPlayers)
} catch (error) {
// do a proper action on failure cases
}
}
现在,如果你的异步操作有错误,它会被 catch
块捕获,你也可以在 catch 块中使用 console.error(error)
或 console.warn(error)
来查看异常和堆栈跟踪。
注意: 将此方法与 try/catch 结合使用将确保应用程序即使在出现异常和错误后仍能继续工作。
使用旧版本的 web3 作为教程 web3@0.20.6 和 Firefox 100.0.1
这是我为解决错误而添加的反应
web3.eth.defaultAccount = web3.eth.accounts[0]
如何在调用智能合约函数时修复此错误?
Uncaught (in promise) Error: invalid address (argument="address", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=address/5.0.5) (argument="index", value={"from":"0xaD1D30B476C195C23ef4CC9b7A3c53E7423B7690"}, code=INVALID_ARGUMENT, version=abi/5.0.7)
这是我的代码:
enter: async function() {
App.contracts["MyContract"].deployed().then(async(instance) =>{
var a = web3.eth.getAccounts();
let ticketsForPlayers = await instance.getTicketsForPlayers({from: App.account});
console.log(ticketsForPlayers);
});
}
问题
错误表明您没有正确设置 address
属性,这可能是您的 solidity
实现的问题,与 javascript 无关片段,如评论中所述,您可以在相关网站上询问它,但上面的片段有一些点可能对您有所帮助。
您在 enter
方法中混合了两种不同的实现来处理明显不正确并导致问题的承诺。
积分
使用 async/await
和 try/catch
块。有关 MDN 文档的更多信息:
enter: async function () {
try {
const instance = await App.contracts["MyContract"].deployed()
const properNameForVariable = web3.eth.getAccounts();
const ticketsForPlayers = await instance.getTicketsForPlayers({from: App.account})
console.log(ticketsForPlayers)
} catch (error) {
// do a proper action on failure cases
}
}
现在,如果你的异步操作有错误,它会被 catch
块捕获,你也可以在 catch 块中使用 console.error(error)
或 console.warn(error)
来查看异常和堆栈跟踪。
注意: 将此方法与 try/catch 结合使用将确保应用程序即使在出现异常和错误后仍能继续工作。
使用旧版本的 web3 作为教程 web3@0.20.6 和 Firefox 100.0.1
这是我为解决错误而添加的反应
web3.eth.defaultAccount = web3.eth.accounts[0]