Skip to content

Commit 3091556

Browse files
author
Achilles Bot
committed
deploy: update testnet deploy script for Hardhat 3.x with proper artifact loading
1 parent ec0ca57 commit 3091556

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

scripts/deploy-basepay-testnet.js

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*
77
* Prerequisites:
88
* 1. Get Base Sepolia ETH from https://docs.base.org/docs/network-information#base-sepolia
9-
* 2. Get Base Sepolia USDC (or use any ERC20 for testing)
10-
* 3. Set env vars below
11-
* 4. Run: node scripts/deploy-basepay-testnet.js
9+
* 2. Set PRIVATE_KEY env var from MetaMask
10+
* 3. Run: node scripts/deploy-basepay-testnet.js
1211
*/
1312

1413
import { ethers } from 'ethers';
1514
import fs from 'node:fs';
1615
import path from 'node:path';
16+
import { fileURLToPath } from 'node:url';
17+
18+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1719

1820
// Base Sepolia USDC (canonical testnet address)
1921
// If unavailable, any ERC20 works for testing
@@ -38,24 +40,34 @@ async function main() {
3840
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
3941

4042
console.log('Deployer:', wallet.address);
41-
console.log('Balance:', ethers.formatEther(await provider.getBalance(wallet.address)), 'ETH');
43+
44+
const balance = await provider.getBalance(wallet.address);
45+
console.log('Balance:', ethers.formatEther(balance), 'ETH');
46+
47+
if (balance === 0n) {
48+
console.error('\nERROR: Wallet has no Sepolia ETH');
49+
console.error('Get Sepolia ETH from: https://docs.base.org/docs/network-information#base-sepolia');
50+
process.exit(1);
51+
}
4252

4353
// Read contract bytecode
44-
const artifactPath = path.resolve('artifacts/contracts/BasePayContract.sol/BasePayContract.json');
54+
const artifactPath = path.resolve(__dirname, '../artifacts/contracts/BasePayContract.sol/BasePayContract.json');
4555
if (!fs.existsSync(artifactPath)) {
4656
console.error('Contract artifact not found. Run: npx hardhat compile');
4757
process.exit(1);
4858
}
4959

5060
const artifact = JSON.parse(fs.readFileSync(artifactPath, 'utf8'));
5161

52-
const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode, wallet);
53-
54-
console.log('Constructor args:');
62+
console.log('\nConstructor args:');
5563
console.log(' USDC:', USDC_BASE_SEPOLIA);
5664
console.log(' Fee:', FEE_USDC_6DP);
5765

66+
// Deploy
67+
const factory = new ethers.ContractFactory(artifact.abi, artifact.bytecode, wallet);
5868
const contract = await factory.deploy(USDC_BASE_SEPOLIA, FEE_USDC_6DP);
69+
70+
console.log('Deploying... tx:', contract.deploymentTransaction().hash);
5971
await contract.waitForDeployment();
6072

6173
const address = await contract.getAddress();
@@ -69,6 +81,25 @@ async function main() {
6981
console.log(` BASE_PAY_USDC_ADDRESS=${USDC_BASE_SEPOLIA}`);
7082
console.log(` BASE_PAY_FEE_USDC=${FEE_USDC_6DP}`);
7183
console.log(` BASE_RPC_URL=${RPC_URL}`);
84+
85+
// Save deployment info
86+
const deploymentInfo = {
87+
network: 'baseSepolia',
88+
contractAddress: address,
89+
usdcAddress: USDC_BASE_SEPOLIA,
90+
feeAmount: FEE_USDC_6DP,
91+
deployer: wallet.address,
92+
timestamp: new Date().toISOString(),
93+
transactionHash: contract.deploymentTransaction().hash
94+
};
95+
96+
const deploymentPath = path.resolve(__dirname, '../deployments/base-sepolia.json');
97+
fs.mkdirSync(path.dirname(deploymentPath), { recursive: true });
98+
fs.writeFileSync(deploymentPath, JSON.stringify(deploymentInfo, null, 2));
99+
console.log('\nDeployment saved to:', deploymentPath);
72100
}
73101

74-
main().catch(console.error);
102+
main().catch(err => {
103+
console.error('Deployment failed:', err);
104+
process.exit(1);
105+
});

0 commit comments

Comments
 (0)