dappuniversity / eth-todo-list

Blockchain Todo App Tutorial Powered by Ethereum Smart Contracts
548 stars 549 forks source link

.deployed() is not a function #33

Open djcolantonio opened 2 years ago

djcolantonio commented 2 years ago

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(window.ethereum)
 //getting values from blockchain
 App.todoList = await App.contracts.TodoList.deployed()
 console.log(App.todoList)

error:

TypeError: App.contracts.TodoList.deployed is not a function

did anyone run into this problem or does anyone know a fix/workaround?

cagilceren commented 2 years ago

you may want to check that. My version does not have that error. https://github.com/dappuniversity/eth-todo-list/issues/32#issue-1250547773

ramiware commented 2 years ago

I was having issues with the deployed() function as well.

I was using Brave but after switching to Chrome it worked. Here is a copy of my code

` loadContract: async () => { // Create a JavaScript version of the smart contract // which allows us to call the functions in the contract (interact with it) const todoList = await $.getJSON('TodoList.json') console.log(todoList) App.contracts.TodoList = TruffleContract(todoList) App.contracts.TodoList.setProvider(App.web3Provider)

// Hydrate the smart contract with values from the blockchain
// This makes it live and accessible
App.todoList = await App.contracts.TodoList.deployed()

}, `

As well as the contract definition

contracts: {}, // create empty contract object

I think a good test is simply if you see the results of the following in the Console then your contract is definitely on the block chain. The error you are getting is environment related, likely a browser issue. Brave is great, but I have come across a number of "issues" with it. I would stick to Chrome for all dev purposes.

console.log(todoList)

djcolantonio commented 2 years ago

I was also using Brave. I will try this and let you know. Thanks for the response !

On Thu, Jun 2, 2022 at 12:43 PM Rami Sorikh @.***> wrote:

I was having issues with the deployed() function as well.

I was using Brave but after switching to Chrome it worked. Here is a copy of my code

` loadContract: async () => { // Create a JavaScript version of the smart contract // which allows us to call the functions in the contract (interact with it) const todoList = await $.getJSON('TodoList.json') console.log(todoList) App.contracts.TodoList = TruffleContract(todoList) App.contracts.TodoList.setProvider(App.web3Provider)

// Hydrate the smart contract with values from the blockchain // This makes it live and accessible App.todoList = await App.contracts.TodoList.deployed()

}`

As well as the contract definition

contracts: {}, // create empty contract object

I think a good test is simply if you see the results of the following in the Console then your contract is definitely on the block chain. The error you are getting is environment related, likely a browser issue. Brave is great, but I have come across a number of "issues" with it. I would stick to Chrome for all dev purposes.

console.log(todoList)

— Reply to this email directly, view it on GitHub https://github.com/dappuniversity/eth-todo-list/issues/33#issuecomment-1145080005, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFK6BWCEIZ2HIJDQS4LG4WDVNDQBPANCNFSM5XHJLI5Q . You are receiving this because you authored the thread.Message ID: @.***>

-- Thank you, Dan Colantonio

ramiware commented 2 years ago

No worries. Hope it works.

Note: Might be worth noting to save you time that the code I provided above is pretty much the original give or take my comments.

djcolantonio commented 2 years ago

@ramiware no luck with this, deployed is not a function, task count is not a function either

ramiware commented 2 years ago

Can you share your TodoList.sol file contents?

CodeMongerrr commented 1 year ago

It occured to me too, apparently I did not migrate my code

Sajramkisho commented 10 months ago

async function main() { const lock = await hre.ethers.getContractFactory("Token"); const token = await lock.deploy();

//ignore this line.

//await token.deploy();

//try to print token.address => you will get object. But the key is not address . address is within runner key . So you have to access it with token.runner.address instead of token.address. //if you try to access with token.address . you will get undefined. because token.address is not there directly. console.log(token.runner.address);

// console.log(token.address); }

// We recommend this pattern to be able to use async/await everywhere // and properly handle errors. main().catch((error) => { console.error(error); process.exitCode = 1; });

Sidhuavneet commented 9 months ago

async function main() { const Upload = await hre.ethers.getContractFactory("Upload"); const upload = await Upload.deploy(); const address = await upload.getAddress(); console.log("Library deployed to:", address); }

//just like in above example i am using BRRAVE browser //using upload.getAddress(); will also get you the address if u dont want to use runner

i101dev commented 9 months ago

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(window.ethereum)
 //getting values from blockchain
 App.todoList = await App.contracts.TodoList.deployed()
 console.log(App.todoList)

error:

TypeError: App.contracts.TodoList.deployed is not a function

did anyone run into this problem or does anyone know a fix/workaround?

I had the same issue and found the answer:

"waitForDeployment"

just like this:

const TokenMaster = await ethers.getContractFactory("TokenMaster");
const tokenMaster = await TokenMaster.deploy(NAME, SYMBOL);
await tokenMaster.waitForDeployment();