-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* First draft of deploying with Hardhat * this is JS, not TS * Use .env
- Loading branch information
1 parent
aff2bf1
commit ae2bf94
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: '👷 Deploy to Etherlink with Hardhat' | ||
--- | ||
|
||
[Hardhat](https://hardhat.org/) is a suite of tools for working with Ethereum contracts and dApps. | ||
You can use Hardhat to deploy contracts to Etherlink just like you use it on other networks: | ||
|
||
1. Set up a new Hardhat project by running `npx hardhat init`. | ||
1. Add Etherlink as a network by putting the Etherlink RPC node and your private key in the `hardhat.config.js` file, as in this example: | ||
|
||
```javascript | ||
import "@nomicfoundation/hardhat-toolbox"; | ||
import 'dotenv/config'; | ||
|
||
const config = { | ||
solidity: "0.8.19", | ||
networks: { | ||
etherlinkTest: { | ||
url: "https://node.ghostnet.etherlink.com", | ||
accounts: [process.env.MY_PRIVATE_KEY], | ||
} | ||
} | ||
}; | ||
|
||
export default config; | ||
``` | ||
|
||
1. Create a contract or use the default contract in the `contracts` folder. | ||
1. Compile the contract by running `npx hardhat compile`. | ||
1. Update the default `scripts/deploy.js` file to deploy your contract. | ||
For example, if your contract is named "MyContract.sol" and accepts a string value and an integer value in the constructor, the deployment script looks like this example: | ||
|
||
```javascript | ||
import { ethers } from "hardhat"; | ||
|
||
async function deployMyContract() { | ||
const deployedContract = await ethers.deployContract("MyContract", ["Hello", 5]); | ||
await deployedContract.waitForDeployment(); | ||
} | ||
|
||
deployMyContract().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); | ||
``` | ||
|
||
1. Run the deployment script on the Etherlink network with this command: | ||
|
||
```bash | ||
npx hardhat run --network etherlinkTest scripts/deploy.js | ||
``` | ||
|
||
This command refers to the `etherlinkTest` network in the Hardhat config file. | ||
|
||
1. Copy the address of the deployed contract from the log. | ||
|
||
Now you can interact with the contract from Hardhat. | ||
For example, if the contract has a function named "DoSomething," you can call it with this code: | ||
|
||
```javascript | ||
import { ethers } from "hardhat"; | ||
|
||
async function callMyContract() { | ||
const MyContract = await ethers.getContractFactory("MyContract"); | ||
const contract = MyContract.attach( | ||
// The deployed contract address | ||
"0xcDd461a8dD3d519111Fe7a4ac2b9563AcEbF5B7c" | ||
); | ||
|
||
await contract.DoSomething(); | ||
} | ||
|
||
callMyContract().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); | ||
``` | ||
|
||
Then you can run this script on the Etherlink network with the command `npx hardhat run --network etherlinkTest scripts/myScript.js`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters