Lesson 6: TypeError: simpleStorage.deployed is not a function #793
-
Hello folks, I get an error : Deploying Contract.... and when I remove it, it works fine!! Also, I put await before SimpleStorageFactory.deploy() and it also worked, isn`t there any difference between await SimpleStorageFactory.deploy() and SimpleStorageFactory.deploy() ?? do you know why? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 11 replies
-
Can you send the entire program (the one used to deploy, where the error is occuring), thanks. |
Beta Was this translation helpful? Give feedback.
-
// * hardhat gets contract from artifacts folder that is the reason it knows contract with name and we can get this way.
const SimpleStorageFactory = await ethers.getContractFactory("SimpleStorage");
console.log("Deploying contract...");
const simpleStorage = await SimpleStorageFactory.deploy();
console.log("Waiting for contract to deployed...");
await simpleStorage.deployed();
console.log("Contract address");
console.log(simpleStorage.address); factory instance has a function |
Beta Was this translation helpful? Give feedback.
-
make sure you have the "await" keyword on the SimpleStorageFactory.deploy(): const simpleStorage = await SimpleStorageFactory.deploy() I got this error also and basically by it not having the await in factory it's trying to call the deployed() method on simpleStorage before the object is returned (i.e. before it actually exists). asynch programming in action! |
Beta Was this translation helpful? Give feedback.
-
If you are using ethers version 6 or higher, remove
try to change:
to
you will get the address. |
Beta Was this translation helpful? Give feedback.
-
use: |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
@hamednasr
factory instance has a function
deploy()
on the other hand after deploying the instance we receive that has a functiondeployed()