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

Fix deploy script for ethers v6 compatibility #800

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dev-araujo
Copy link

This PR updates the deploy.js script to be compatible with the latest version of ethers.js (v6).

Problem:

When attempting to deploy our HelloWorld contract using npx hardhat run scripts/deploy.js --network sepolia, the script throws the following error:

Deploying Contract...
TypeError: Cannot read properties of undefined (reading 'hash')
at main (/home/dev-araujo/Documents/github/blockchain-projects/meta-school/Hello-World/scripts/deploy.js:22:47)
at processTicksAndRejections (node:internal/process/task_queues:95:5)

Solution

The deploy.js script was using deprecated methods from older versions of ethers.js. This update addresses these issues by migrating to the new API introduced in v6. Specifically:

  • ContractFactory.deploy() now directly returns the deployed contract instance. The deployTransaction property is no longer available.
  • Replaced provider.waitForTransaction(txHash) with contract.waitForDeployment(), which is the recommended way to wait for deployment confirmation in ethers v6.
  • Replaced accessing txReceipt.contractAddress with contract.getAddress(), a new method to get the deployed contract address.
  • Removed the use of .hash directly as it is not needed anymore.
  • added const { ethers } = require("hardhat"); to make sure that hardhat is correctly imported.

These changes ensure that the script functions correctly with the updated library and avoids potential errors.

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

Successfully merging this pull request may close these issues.

1 participant