Ich versuche, ehter mit diesem Code zu senden
web3.eth.accounts.wallet.add(privateKey);
web3.eth.sendTransaction({
to:someAddress,
from:onwer,
value:amount*1,
gasPrice:result,
gas:21000,
nonce:nonce
}).
then(function (r) {
res.json({
response:r
})
}).catch(function(err){
res.json({error:err.message+"unknown tx"});
});
Ich bekomme immer
error: unknown account
Aber ich füge die Sender-Wallet explizit in diesem Teil hinzu
web3.eth.accounts.wallet.add(privateKeyHere);
result is fetched from web3.eth.getGasPrice() Promise
nonce is fetched web3.eth.getTransactionCount(sender_address_here) Promise
Was ist mit dem Code falsch?
Kann ich Ether ohne sendSignedTransaction oder andere Methoden senden?
Welches ist die beste (und einfachste) Methode, um Ether zu senden, wenn Sie einen privaten Schlüssel mit web3 haben?
Danke
BEARBEITEN 1 Konto wurde erstellt mit
web3.eth.accounts.create();
Bei der Beantwortung meiner eigenen Frage habe ich mit diesem Code eine Lösung gefunden
var Web3 = require("web3");
const web3 = new Web3('http://localhost:8545');
var connection = require("../services/connection");
const axios = require('axios');
const EthereumTx = require('ethereumjs-tx');
let response = axios.get('https://ethgasstation.info/json/ethgasAPI.json').
then(function (response) {
let prices = {
low: response.data.safeLow / 10,
medium: response.data.average / 10,
high: response.data.fast / 10
}
let nonce = web3.eth.getTransactionCount(token.public).then(function (nonce) {
let sendAmount = (prices.high * 1e9) + (prices.high * 1e8);
let details = {
"to": user.public,
"value": sendAmount,
"gas": 21000,
"gasPrice": prices.low * 1e9,
"nonce": nonce,
"chainId": 4 //chainId - mainnet: 1, rinkeby: 4
}
const transaction = new EthereumTx(details)
transaction.sign(Buffer.from(your_pv_key_without0xprefix, 'hex'))
const serializedTransaction = transaction.serialize()
web3.eth.sendSignedTransaction('0x' + serializedTransaction.toString('hex')).
then(function (transactionDetails) {
//handle transaction details
}).catch(function (err) {
res.json({error: err.message});
})
}).catch(function (err) {
res.json({error: err.message});
})
}).catch(function (err) {
res.json({error: err.message});
})
rahul_eth