为什么我的代码()不是一个函数?

发布于 2025-02-03 05:02:18 字数 989 浏览 3 评论 0原文

代码:

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2025-02-10 05:02:18

我在处理硬汉时也有类似的错误
我认为.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 removed

Try .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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文