Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.deployed() is not a function #33

Open
djcolantonio opened this issue May 28, 2022 · 10 comments
Open

.deployed() is not a function #33

djcolantonio opened this issue May 28, 2022 · 10 comments

Comments

@djcolantonio
Copy link

djcolantonio commented May 28, 2022

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
Copy link

you may want to check that. My version does not have that error.
#32 (comment)

@ramiware
Copy link

ramiware commented Jun 2, 2022

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
Copy link
Author

djcolantonio commented Jun 2, 2022 via email

@ramiware
Copy link

ramiware commented Jun 2, 2022

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
Copy link
Author

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

@ramiware
Copy link

ramiware commented Jun 5, 2022

Can you share your TodoList.sol file contents?

@CodeMongerrr
Copy link

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

@Sajramkisho
Copy link

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
Copy link

Sidhuavneet commented Sep 28, 2023

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
Copy link

i101dev commented Oct 12, 2023

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants