Skip to content

Commit d8884e6

Browse files
author
Michael Spengler
committed
minimal viable scope for my hobby projects :)
1 parent 7cab94e commit d8884e6

File tree

1 file changed

+0
-67
lines changed

1 file changed

+0
-67
lines changed

web3-server/web3-server.js

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11

2-
// https://ethereum.stackexchange.com/questions/42929/send-payment-from-wallet-using-web3
3-
// https://web3js.readthedocs.io/en/v1.2.7/web3-utils.html#tohex
4-
52

63
const fs = require('fs-sync')
74
const path = require('path')
85
const express = require('express')
9-
const axios = require('axios')
106
const Web3 = require('web3');
117
const Tx = require('ethereumjs-tx').Transaction;
128
const http = require('http')
@@ -17,7 +13,6 @@ const configFileId = path.join(path.resolve(''), './web3-server/.env.json')
1713
const config = fs.readJSON(configFileId)
1814

1915
const web3 = new Web3(new Web3.providers.HttpProvider(`https://mainnet.infura.io/v3/${config.infuraProjectId}`));
20-
// let web3 = new Web3(Web3.givenProvider)
2116

2217
executeMasterplan()
2318
.then((result) => {
@@ -35,18 +30,8 @@ async function executeMasterplan() {
3530
function defineRoutes(app) {
3631

3732
app.get('/sendSignedTransaction', async (req, res) => {
38-
// var privateKey = Buffer.from('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');
3933
var privateKey = Buffer.from(req.query.privateKey, 'hex');
4034

41-
// var rawTx = {
42-
// nonce: '0x00',
43-
// gasPrice: '0x09184e72a000',
44-
// gasLimit: '0x2710',
45-
// to: '0x0000000000000000000000000000000000000000',
46-
// value: '0x00',
47-
// data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
48-
// }
49-
5035
var nonce = await web3.eth.getTransactionCount(req.query.fromAddress);
5136
console.log(`\n\nnonce: ${nonce}`)
5237

@@ -59,31 +44,21 @@ function defineRoutes(app) {
5944
const myAmount = web3.utils.toHex(req.query.amountToBeSent)
6045
console.log(`\n\nmyAmount: ${myAmount}`)
6146

62-
// console.log(amountToBeSent)
63-
64-
// const rawTransaction = {
65-
// "from": fromAddress,
66-
// "nonce": web3.utils.toHex(nonce),
6747
var rawTx = {
6848
nonce,
6949
gasPrice: myGasPrice,
7050
gasLimit: myGasLimit,
7151
fromAddress: req.query.fromAddress,
7252
to: req.query.toAddress,
7353
value: myAmount,
74-
// data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
7554
}
7655

77-
// var tx = new Tx(rawTx, { 'chain': 'mainnet' });
7856
var tx = new Tx(rawTx);
7957

8058
tx.sign(privateKey);
8159

8260
var serializedTx = tx.serialize();
8361

84-
console.log(serializedTx.toString('hex'));
85-
// 0xf889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f
86-
8762
web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
8863
.on('receipt', console.log);
8964

@@ -117,45 +92,3 @@ function startListening(app) {
11792
console.log(`listening on : http://localhost:${config.httpPort}`)
11893
}
11994
}
120-
121-
122-
async function transfer(fromAddress, toAddress, amountToBeSent, privateKey, chainId = 4) {
123-
124-
console.log(`preparing transaction with \n${fromAddress} \n${toAddress} \n${amountToBeSent} \n${privateKey} \n${chainId}`)
125-
126-
const EthereumTx = require('ethereumjs-tx').Transaction
127-
const privateKeyBuffer = Buffer.from(privateKey, 'hex')
128-
129-
var nonce = web3.eth.getTransactionCount(fromAddress);
130-
131-
const myGasPrice = (await web3.eth.getGasPrice()) * 10
132-
133-
console.log(amountToBeSent)
134-
135-
const rawTransaction = {
136-
"from": fromAddress,
137-
"nonce": web3.utils.toHex(nonce),
138-
"gasPrice": web3.utils.toHex(myGasPrice),
139-
"gasLimit": web3.utils.toHex(33000),
140-
// "gasLimit": '0x2710',
141-
"to": toAddress,
142-
"value": amountToBeSent,
143-
// "chainId": chainId //remember to change this
144-
};
145-
146-
const tx = new EthereumTx(rawTransaction)
147-
tx.sign(privateKeyBuffer)
148-
149-
const serializedTx = tx.serialize()
150-
151-
console.log(`this is getting serious :)`)
152-
153-
web3.eth.sendTransaction('0x' + serializedTx.toString('hex'), function (err, hash) {
154-
if (!err) {
155-
console.log('Txn Sent and hash is ' + hash);
156-
}
157-
else {
158-
console.error(err);
159-
}
160-
});
161-
}

0 commit comments

Comments
 (0)