I am using a JSON RPC request and source code is as follows:
var options ={
url: "http://127.0.0.1:8545",
method: "POST",
headers: {"Content-Type":"application/json"}
};
var tx = {from: req.body.fromaddress, to: req.body.toaddress, value: web3.utils.toWei(req.body.amount, "ether")};
options.body = JSON.stringify({"jsonrpc":"2.0", "method":"personal_sendTransaction", "params":[tx, req.body.password], "id":"curltest"});
callback = (err, response, body) => {
if (!err && response.statusCode == 200) {
const data = JSON.parse(body);
console.log(data);
res.send(data);
}
if (err) {
console.error(err);
res.send(err);
}
};
request(options, callback);
Best Answer
Your
value
field oftx
must be pre-pended with0x
. If thevalue
is0
, thentx.value
must be0x0.
.