-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex4.js
117 lines (106 loc) · 2.89 KB
/
index4.js
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
const axios = require('axios');
const {Web3} = require('web3');
var web3 = new Web3('http://localhost:8545');
// This is an example, replace it with your own contract's ABI
const contractABI = [
{
"inputs": [],
"name": "attack1_int_overflow",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "attack2_reentrancy",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "no_reentrancy",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "attacker2Address1",
"outputs": [
{
"internalType": "contract reentrancy_attack",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "benignUserAddress1",
"outputs": [
{
"internalType": "contract no_reentrancy_attack",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "multiVulnToken",
"outputs": [
{
"internalType": "contract MultiVulnToken",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
// Finding the function signature
const functionSignature = web3.eth.abi.encodeFunctionSignature(contractABI.find(x => x.name === 'attack1_int_overflow'));
console.log(functionSignature)
// 2. Create account variables
const accountFrom = {
privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
};
const contractAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'; // Change addressTo
async function send() {
try {
console.log(`Attempting to send transaction from ${accountFrom.address} to ${contractAddress}`);
const nonce = await web3.eth.getTransactionCount(accountFrom.address, "latest");
const rawTx = {
from: accountFrom.address,
to: contractAddress,
nonce: web3.utils.toHex(nonce),
gasPrice: web3.utils.toHex(web3.utils.toWei('10', 'gwei')),
gasLimit: web3.utils.toHex(300000),
data: functionSignature,
};
const signedTx = await web3.eth.accounts.signTransaction(rawTx, accountFrom.privateKey);
const response = await axios.post('http://localhost:8545', {
jsonrpc: '2.0',
method: 'eth_sendRawTransaction',
params: [signedTx.rawTransaction],
id: 1,
});
console.log("The hash of your transaction is: ", response.data.result,
"\nCheck Transactions tab in your Ethereum client to view your transaction!");
} catch (error) {
console.log("Something went wrong while submitting your transaction:", error);
}
};
send();