-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
153 lines (117 loc) · 4.43 KB
/
Copy pathdeploy.js
File metadata and controls
153 lines (117 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require('dotenv').config();
const { ethers } = require('ethers');
const fs = require('fs');
async function main() {
console.log('Deploying TipJar to Arc Testnet...\n');
// Check for required environment variables
if (!process.env.PRIVATE_KEY) {
console.error('Error: PRIVATE_KEY not found in .env file');
process.exit(1);
}
// Arc Testnet RPC URL
const rpcUrl = process.env.ARC_RPC_URL || 'https://rpc.testnet.arc.io';
// USDC token address on Arc Testnet
const usdcTokenAddress = '0x3600000000000000000000000000000000000000';
// Setup provider and wallet
const provider = new ethers.JsonRpcProvider(rpcUrl);
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
console.log('Deploying from address:', wallet.address);
console.log('USDC token address:', usdcTokenAddress);
// Check USDC balance
const usdcAbi = [
'function balanceOf(address account) view returns (uint256)',
'function decimals() view returns (uint8)',
'function symbol() view returns (string)',
'function name() view returns (string)'
];
const usdcContract = new ethers.Contract(usdcTokenAddress, usdcAbi, provider);
const usdcBalance = await usdcContract.balanceOf(wallet.address);
const usdcDecimals = await usdcContract.decimals();
const usdcSymbol = await usdcContract.symbol();
console.log(`${usdcSymbol} balance:`, ethers.formatUnits(usdcBalance, usdcDecimals));
console.log(`${usdcSymbol} decimals:`, usdcDecimals.toString());
if (usdcBalance === 0n) {
console.error('Warning: You have 0 USDC balance. You will not be able to test tipping.');
}
// Load ABI and bytecode
const abi = JSON.parse(fs.readFileSync('TipJar_abi.json', 'utf8'));
const bytecodeData = JSON.parse(fs.readFileSync('TipJar_bytecode.json', 'utf8'));
const bytecode = bytecodeData.bytecode;
// Create contract factory
const factory = new ethers.ContractFactory(abi, bytecode, wallet);
console.log('\nDeploying TipJar contract...');
// Deploy the contract with USDC token address
const contract = await factory.deploy(usdcTokenAddress);
await contract.waitForDeployment();
const contractAddress = await contract.getAddress();
console.log('\nTipJar deployed successfully!');
console.log('Contract address:', contractAddress);
console.log('USDC token:', usdcTokenAddress);
// Save deployment info
const deploymentInfo = {
network: 'Arc Testnet',
contractAddress: contractAddress,
usdcTokenAddress: usdcTokenAddress,
deployer: wallet.address,
deployedAt: new Date().toISOString(),
contractName: 'TipJar',
tokenStandard: 'USDC (ERC20)'
};
fs.writeFileSync('deployment.json', JSON.stringify(deploymentInfo, null, 2));
console.log('\nDeployment info saved to deployment.json');
// Update README with deployment info
const readmeContent = `# TipJar - USDC Tipping DApp
A decentralized application for sending USDC tips on the Arc blockchain.
## Deployed Contract
- **Network:** Arc Testnet
- **Contract Address:** ${contractAddress}
- **USDC Token:** ${usdcTokenAddress}
- **Deployer:** ${wallet.address}
- **Deployed At:** ${new Date().toISOString()}
## How to Use
### Prerequisites
- Node.js and npm installed
- Arc Testnet account with USDC tokens
### Installation
\`\`\`bash
npm install
\`\`\`
### Compile
\`\`\`bash
npm run compile
\`\`\`
### Deploy
1. Create a \`.env\` file with your private key:
\`\`\`
PRIVATE_KEY=your_private_key_here
\`\`\`
2. Run deployment:
\`\`\`bash
npm run deploy
\`\`\`
### Test
\`\`\`bash
node test.js
\`\`\`
## Contract Functions
- \`sendTip(address recipient, uint256 amount, string message)\` - Send a USDC tip
- \`withdrawTips()\` - Withdraw tips received
- \`getContractBalance()\` - Get contract USDC balance
- \`getStats()\` - Get total tips and tippers
- \`tipsReceived(address)\` - Get total tips received by address
- \`tipsSent(address)\` - Get total tips sent by address
## Features
- USDC tipping
- Track total tips and unique tippers
- Secure ERC20 transfers
- Support for custom messages (max 280 chars)
## License
MIT
`;
fs.writeFileSync('README.md', readmeContent);
console.log('README updated with deployment info');
}
main().catch((error) => {
console.error('Deployment failed:', error);
process.exit(1);
});