This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark_http.js
60 lines (52 loc) · 1.76 KB
/
benchmark_http.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
const Web3 = require('web3');
const axios = require('axios');
const nodeUrl = 'http://localhost:7545';
const web3 = new Web3.Web3('http://localhost:7545')
var data = require('./requests.json');
async function main() {
console.log("RUNNING ON ANVIL LOCAL FORK OVER HTTP WITH WEB3.JS")
const start = Date.now();
for (tx of data) {
tt = tx['type'];
params = tx['params'];
if (tt == 'eth_send') {
let reciept = await web3.eth.sendTransaction(params);
} else if (tt == 'eth_call') {
let body = {
jsonrpc: '2.0',
method: 'eth_call',
params: params,
id: 1,
};
await axios.post(nodeUrl, body)
.then(response => {
//console.log('Response:', response.data.result);
})
.catch(error => {
console.error('Error:', error);
});
// console.log("RESULT", result);
} else if (tt == 'eth_sendTransaction') {
let body = {
jsonrpc: '2.0',
method: 'eth_sendTransaction',
params: params,
id: 1,
};
await axios.post(nodeUrl, body)
.then(response => {
//console.log('Transact Response:', response.data.result);
})
.catch(error => {
console.error('Error:', error);
});
} else {
throw new Error('AAAAA!');
}
// console.log(tx);
}
const end = Date.now();
console.log(`Web3.js HTTP Anvil: ${(end - start) / 1000} seconds\n`);
}
// Call the main function to initiate the transaction
main();