Deploy Contract

Yan Ru Su

Use Arbitrum Sepolia testnet

https://dashboard.alchemy.com/apps/j3k2fv9o3o9wje2x/setup

拿 Node RPC API

Setting ALCHEMY API

npx hardhat vars set “varible name”

1
npx hardhat vars set ALCHEMY_API_KEY

Create Arbitrum Sepolia account

use private key

1
npx hardhat vars set ARBITRUM_SEPOLIA_PRIVATE_KEY

Setting network

在hardhat.config.js的module.exports設定網路

1
2
3
4
5
6
networks: {
arbitrumSepolia: {
url: `https://arb-sepolia.g.alchemy.com/v2/${ALCHEMY_API_KEY}`,
accounts: [ARBITRUM_SEPOLIA_PRIVATE_KEY],
},
},

Create scripts dictionary

1
mkdir scripts

Create deploy.js

1
touch deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
const { ethers } = require("hardhat");

async function main() {
const Token = await ethers.getContractFactory("Token");//要放你要deploy的contract的名字
const token = await Token.deploy();
console.log(`Token deployed at: ${token.target}`);
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});

Use commad

1
npx hardhat run-- network arbitrumSepolia scripts/deploy.js 

terminal will show the contract address

1
0xe8f6dab9045c9ce68d37ea95e416d54e7e5678ef

you can search the address on the arbiscan.io

https://sepolia.arbiscan.io/address/0xe8f6dab9045c9ce68d37ea95e416d54e7e5678ef