I have a geth server that I need to transfer some ethereum to other wallet. I studdied the wiki page of geth and found out there is a method called sendTransaction for this job.
First: I used the following command to transfer money, the resault gave me a transaction hash but it didn't transfer money to the desired wallet.
eth.sendTransaction({from:eth.coinbase, to:"WALLET-Address", value: web3.toWei(0.05, "ether")});
response: 0x....
Second: I used combination of some gas and gasPrice parameters to do the transaction but the result was the same. like this one:
eth.sendTransaction({from:eth.coinbase, to:"WALLET-Address", value: web3.toWei(0.05, "ether"), gas: 100000, gasPrice: web3.toWei(14000,'gwei')})
response: 0x...
Important i have to mention, the transaction didn't show up in etherscan.io.
please help me to figure out this problem. Thanks.
EDITED
It is not my own private network. this is a project and i am coding for someone else
I this is my JS code to, Please tell me what is the problem
#!/usr/bin/nodejs
var loadedWeb3 = require('web3');
var web3 = new loadedWeb3();
const URL = 'http://<IP>:8545';
web3.setProvider(new web3.providers.HttpProvider(URL));
var req = {
to:"My-Wallet",
from: "SourceWallet",
value: web3.utils.toWei('1', 'ether'),
gasLimit : 21000,
gasPrice : 20000000000
};
web3.eth.getTransactionCount(req.from).then(console.log);
web3.eth.sendTransaction(req)
.on('transactionHash', function(hash){
console.log("TxHash: " + hash);
web3.eth.getTransaction(hash).then(console.log);
})
.on('receipt', function(receipt){
console.log("Receipt: " + receipt);
console.log(receipt);
})
.on('confirmation', function(confirmationNumber, receipt){
console.log("confirmed -> " + confirmationNumber);
console.log(confirmationNumber);
console.log("Receipt -> " + receipt);
console.log(receipt);
})
.on('error', console.error);
First: You need funds. To send ether you need ether. To send 0.05 ether you probably gonna spend 0.06 (0.05 + 0.01 transaction costs).
Second: You need to have the wallet unlocked at your node.
Third: check if eth.coinbase has funds as it is the wallet you are trying to get ether from. I would advise you to check if eth.accounts[0] has funds too.
At the end, I would advise you to try things on a private network before using the real network. It's a lot easier and cheaper.
Additional information
I used following code in NodeJS for money transfer I got Transaction Hash + 25 Confirmations but no money transferred.
#!/usr/bin/nodejs
var loadedWeb3 = require('web3');
var web3 = new loadedWeb3();
const URL = 'http://<IP>:8545';
web3.setProvider(new web3.providers.HttpProvider(URL));
var req = {
to:"Destination Wallet",
from: "Source Wallet",
value: web3.utils.toWei('1', 'ether')
};
web3.eth.sendTransaction(req)
.on('transactionHash', function(hash){
web3.eth.getTransaction(hash).then(function(trans) {
var line = "====================================";
console.log(line + " Transaction " + line);
console.log(" From: " + trans.from);
console.log(" To: " + trans.to);
console.log("Trans Hash: " + trans.hash);
console.log(" Ethereum: " + web3.utils.fromWei(trans.value.toString(), 'ether'));
console.log(" Gas Limit: " + trans.gas);
console.log(" Gas Price: " + web3.utils.fromWei(trans.gasPrice.toString(), 'Gwei'));
});
})
.on('receipt', function(receipt){
var line = "======================================";
console.log(line + " Receipt " + line);
console.log("Block Hash: " + receipt.blockHash);
console.log("Block Code: " + receipt.blockNumber);
console.log(" Used Gas: " + receipt.gasUsed);
console.log(line + "=========" + line);
})
.on('confirmation', function(confirmationNumber, receipt){
console.log("Confirm Code: " + confirmationNumber);
})
.on('error', console.error);
and the Following response appeared:
==================================== Transaction ====================================
From: 0x1234400000000000000000000000000000000000
To: 0x1234500000000000000000000000000000000000
Trans Hash: 0xeaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Gas Limit: 90000
Gas Price: 0.00009
Confirm Code: 0
====================================== Receipt ======================================
Block Hash: 0x8bcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
Block Code: 41962
Used Gas: 21000
=====================================================================================
Confirm Code: 1
Confirm Code: 2
Confirm Code: 3
Confirm Code: 4
Confirm Code: 5
Confirm Code: 6
Confirm Code: 7
Confirm Code: 8
Confirm Code: 9
Confirm Code: 10
Confirm Code: 11
Confirm Code: 12
Confirm Code: 13
Confirm Code: 14
Confirm Code: 15
Confirm Code: 16
Confirm Code: 17
Confirm Code: 18
Confirm Code: 19
Confirm Code: 20
Confirm Code: 21
Confirm Code: 22
Confirm Code: 23
Confirm Code: 24
but the transaction is not in https://etherscan.io and money didn't transfer.
Related
I'm creating a React game. In this game, the user can buy card packs. He has an amount of money (called essences) and can chose any type of packs he wants to purchase (mini packs cost 500, normal are 1500 and mega packs cost 3000).
For every type of pack, I have an onClick button that triggers a function (BuyPack) with a parameter (the cost of the selected pack).
⏫Here is the 500 essences pack.
The function then makes an axios call to my express server :
const BuyPack = (arg) => {
let nb = (document.getElementById('essences').innerText) // that obviously sucks lol
let nbInt = parseInt(nb) // converts innerText to int
const newSolde = (nbInt - arg) // The calculated amount after the purchase
// Update visually the amount of essences
localStorage.setItem('essences', newSolde)
document.getElementById('essences').innerHTML = newSolde; // Let's set the new amount
let datas = {id: localStorage.getItem('id'), typeOfPack: arg}; // id = the user id / arg = 500, 1500 or 3000, it's basically the pack price.
console.log('datas', datas) // Output : datas {id: '196', typeOfPack: 500}
Axios.post('http://localhost:3001/buyPack', {data: datas}) // The axios call that doesn't work as expected
}
The axios call is :
app.post('/buyPack', function (req, res) {
const userId = (req.body.data.id)
const typeOfPack = (req.body.data.typeOfPack)
console.log(typeOfPack)
// I make a first request to get the "pre-buy" amount of money
query("select essences FROM users WHERE id = ?", [userId], (err, rows) => {
const actualEssences = (rows[0].essences); // The amount we just got
// Second query where we update and decrease the amount of money for the user
query("update users set essences = " + (actualEssences - typeOfPack) + " where id = " + userId)
})
})
For some reason I don't get, after some purchases, my express server just doesn't respond anymore. (the 3000 below are the console.log(typeOfPack).
Client side, I have no problem, the money is decreasing and I get the console message that I clicked on the pack.
I've tryied many things, but I really can't see the the issue comes from.
Thanks a lot in advance.
I am trying to create a script that will show the bus times from my local stop on a scrollphatHD on raspberry pi zero w.
I can get the script running and I get the correct bus times, but I am having trouble getting the new bus times without restarting the script.
How can I loop the bus times so that I always get the updated times?
import requests
import signal
import scrollphathd
from scrollphathd.fonts import font3x5
r = requests.get("https://skyss.giantleap.no/public/departures?Hours=1&StopIdentifiers=12015491")
dest = r.json()["PassingTimes"][0]["TripDestination"]
avgang = r.json()["PassingTimes"][0]["DisplayTime"]
dest2 = r.json()["PassingTimes"][1]["TripDestination"]
avgang2 = r.json()["PassingTimes"][1]["DisplayTime"]
linje2 = dest + " " + avgang + ", " + dest2 + " " + avgang2 + ", "
while True:
scrollphathd.write_string(str1, y=1, font=font3x5, brightness=0.5)
scrollphathd.flip(x,y)
scrollphathd.scroll()
scrollphathd.show()
print(linje2)
I want the result to be updated about every 20 seconds or so, but I end up just getting the time from when I start the script over and over.
I want the extension to count how many times the browser was opened.
Below is the piece of code which should do the job, but does not work as
expected. Why?
chrome.runtime.onStartup.addListener(function() {
chrome.storage.sync.get({'number' : 1}, function(result) {
// prints 1 the first time, then keeps printing 2 all the time, why?
console.log("Old number is " + result.number);
// Trying to increment 'number' value by 1
chrome.storage.sync.set({'number' : (result.number + 1)},
function() {})
});
});
I'm not sure you should be using "1" in get...
chrome.runtime.onStartup.addListener(function() {
chrome.storage.sync.get(['number'], function(result) {
let number;
if ('number' in result)
number = result.number;
else
number = 1;
// prints 1 the first time, then keeps printing 2 all the time, why?
console.log("Old number is " + number);
number += 1;
// Trying to increment 'number' value by 1
chrome.storage.sync.set({number: number},
function() {console.log("value as set to " + number);});
});
});
This code should probably be on a "background script", and the only console that will show anything is the console you open from "tools, more tools, extensions" and click the view link in your listed extension.
If you're having problems with syncing as mentioned in comments, you can try using chrome.storage.local.get / set.
I think that for what you're doing, this is better.
This is the case. I want to make a game, client being made in flash and server on java. From server side, the first byte i write on the stream is the protocol id, like this:
try
{
Output.writeByte(LOGIN);
Output.writeByte((byte)ID);
Output.writeByte(new_position.x);
Output.writeByte(new_position.y);
Output.flush();
}
After the 'onResponse' event is triggered, the socket is read like this:
type:int = socket_client.readByte();
if (type == 0x1)
FP.console.log("You are logged as " + socket_client.readByte() + " in x:" + socket_client.readByte() + " y:" + socket_client.readByte() );
else if (type == 0x2)
FP.console.log("You are now in x:" + socket_client.readByte() + " y:" + socket_client.readByte());
As you probably have guessed by now, this gives me some problems. Sometimes, server sends the information split in two, so the above code throws an EOF exception. Tracing the following code gives me sometimes this result:
trace("SIZE: " + socket_client.bytesAvailable);
//var type:int = socket_client.readByte();
var values:String = "";
while (socket_client.bytesAvailable > 0)
values += socket_client.readByte() + " ";
trace(values);`
Values:
SIZE: 1
2
SIZE: 2
2 6
The first '2' is the protocol id, the second and the third stands for x and y values.
Now, the question is, how can i prevent this to happen? How could i 'wait' until i have all the information needed?
Btw, on java this never happens, but i have no more control than on as3.
Add BufferedOutputStream in output initialization like this:
Output = new DataOutputStream(new BufferedOutputStream(connection.getOutputStream()));
Basically you need to switch your message format from [type, data] to [type, length, data]. Then, wait to process the data until bytesAvailable >= length, otherwise put it into a buffer.
Here is an example SOCKET_DATA handler that uses this logic:
https://github.com/magicalhobo/Flash-CS5-mobile-proxy/blob/master/com/magicalhobo/mobile/proxy/MobileClient.as#L110
I have a small Google Apps Script that processes a date column in a spreadsheet and generates entries in a Calendar (birthdays).
Work is fine, but when adding reminders to the (recently-created) CalendarEvent, an error is thrown :
Service error: CalendarApp: Mismatch: etags = ["GUQKRgBAfip7JGA6WhJb"], version = [63489901413]
I've tried to perform 1 second sleep after creating event (wait for changes to be done in calendar), but no luck on this...
BTW, events are created succesfully, only reminders cannot be added.
PD: the calendar is one I own, but not my primary calendar.
Here is part of the code:
try
{
birthday = new Date(Data[i][BirthColumn]);
birthday.setFullYear(today.getFullYear());
birthday.setUTCHours(12);
birthlist += Data[i][NameColumn] + " --> " + birthday + "\n";
calendarevent = cal.createAllDayEventSeries("¡Cumpleaños " + Data[i][NameColumn] + "!", birthday, CalendarApp.newRecurrence().addYearlyRule().times(YearsInAdvance));
if (calendarevent == null)
success = false;
else
{
//This sentence fails every single time.
calendarevent.addEmailReminder(0);
calendarevent.addPopupReminder(0);
calendarevent.addSmsReminder(0);
}
}
catch (ee)
{
var row = i + 1;
success = false;
errlist += "Error on row " + row + ": check name and birth date. Exception Error: " + ee.message + "\n";
}
This is the portion of the code I finally change to make it work, as Serge insas suggest me before:
if (calendarevent == null)
success = false;
else
{
cal.getEventSeriesById(calendarevent.getId()).addEmailReminder(0);
cal.getEventSeriesById(calendarevent.getId()).addPopupReminder(0);
cal.getEventSeriesById(calendarevent.getId()).addSmsReminder(0);
}
This is a known issue
See comment nr 67 for a working workaround : the trick is to re-call the event for every item you want to add (reminder, popup...) using cal.getEventSeriesById(eventID) after you get the Id simply with .getId()
I use it in some scripts and it solved the issue for me.