为什么我的代码()不是一个函数?
代码:
loadContract: async ()=>{
//Create JS version of smart contract
const todoList = await $.getJSON('TodoList.json')
App.contracts.TodoList = TruffleContract(todoList)
App.contracts.TodoList = web3.setProvider(new Web3.providers.HttpProvider("http://127.0.0.1:7545"))
//getting values from blockchain
App.todoList = await App.contracts.TodoList.deployed()
console.log(todoList)
错误:
typeerror:app.contracts.todolist.deployed不是函数
我可以在松露dev环境中调用todolist.deployed()的函数,而是在JavaScript文件中调用。我正在尝试将已部署的智能合约中的所有数据设置为app.todolist,以便我可以使用JavaScript文件中的值并将其渲染到HTML。我完全被困。当我console.log(Todolist)
时,我会收到智能合约的JSON。
这是我的迁移文件。
//need migration to update state of blockchain
const TodoList = artifacts.require("./TodoList.sol");
module.exports = function (deployer) {
deployer.deploy(TodoList);
};
//run migration and deploy contract to blockchain
code:
loadContract: async ()=>{
//Create JS version of smart contract
const todoList = await $.getJSON('TodoList.json')
App.contracts.TodoList = TruffleContract(todoList)
App.contracts.TodoList = web3.setProvider(new Web3.providers.HttpProvider("http://127.0.0.1:7545"))
//getting values from blockchain
App.todoList = await App.contracts.TodoList.deployed()
console.log(todoList)
error:
TypeError: App.contracts.TodoList.deployed is not a function
I am able to call TodoList.deployed() in the truffle dev environment but not in the JavaScript file. I am trying to to set all the data from the deployed smart contract to App.todoList so I can work with the values in the JavaScript file and render them to the HTML. I am completely stuck. When I console.log(todolist)
I receive the JSON of the smart contract.
Here is my migrations file.
//need migration to update state of blockchain
const TodoList = artifacts.require("./TodoList.sol");
module.exports = function (deployer) {
deployer.deploy(TodoList);
};
//run migration and deploy contract to blockchain
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在处理硬汉时也有类似的错误
我认为
.deployed()
函数可以被弃用或删除,请尝试
.waitfordeployment()
,这使我同样地消失了这个错误
如果您想找出答案, 合同地址
然后,不用使用
< contractvariable_name> .address
使用
< contractvariable_name> .target
这应该为您提供帮助(甚至可能是任何其他读者)
I have a similar error while dealing with hardhat
I'm thinking the
.deployed()
function may be deprecated or removedTry
.waitForDeployment()
That made the error go away for me
Similarly, if you want to find out the contract address
then instead of using
<contractVariable_name>.address
Use
<contractVariable_name>.target
This should help you (and possibly any further readers)