Web3.js >> w3.eth.sendSignedTransaction the txn is submitted but not succesful - node.js

Description::
I've a signed txn and when I submit it using w3.eth.sendSignedTransaction , I see the following logs in my Geth log file
Geth logs are as follows:
INFO [05-24|12:01:44] Submitted transaction fullhash=0xd6ad180c709ce93f5884070f28488925e9b944a24fc6ab737c79d8e66dfd9dca recipient=0xF06c0a4A9fafddA7b8B25F986e1C0dfEC62e1E84
I obtain the txn hash as shown above but now when I try to search my txn using the hash , following is what I get >>
My question is :: Why the block hash is >> 0x0000 . . . . . ?
What could be wrong here ?
The code which is use to send this txn is as follows >>
w3.eth.sendSignedTransaction( data ).once( 'transactionHash', (hash) => {
console.log(hash)
}).on('receipt', (receipt) => {
console.log('receipt');
}).on('confirmation', (confirmationNumber, receipt) => {
console.log('confirmation');
}).on('error', (err) => {
console.log(err);
}).then( (receipt) => {
console.log('finally got the receipt!');
})
.catch(e => {
console.log('err');
})

I had the same issue.
This problem comes when our nonce is not one higher than the count of transactions from the account.
Check whether the following equation is true in your case >>
NONCE = count_of_transactions_from_account + 1
Hope that helps!!!

Related

Node.js: Multiple inputs from user in an interactive CLI

I'm trying to create a simple interactive CLI with Node.js, that collects input from the user by "talking" to them asking questions.
I'm working with the 'readline' module that forces me to use the callback mechanism, currently results in the weird cascade below.
As I'm new to Node.js and to the callback idea, I really feel I'm doing something wrong but not sure how to make it better.
How can I reformat my function so it will be more elegant?
(I know the function below won't return anything, it's just for my temp debugging)
function getUserInput(dbData) {
readline.question('What would you like to edit?\n\n\t(1) Cars\t(2) Data owners\n', choice => {
if (choice == 1) {
readline.question('Choose operation:\n\n\t(1) Add new\n', op => {
if (op == 1) {
let newCar = {};
console.log("--> Please fill in the required details (with Capital First Letter):\n\n");
readline.question("Car name: ", carName => {
newCar.name = carName;
readline.question("Car make: ", carMake => {
newCar.make = carMake;
readline.question("Team (DC/CSF): ", team => {
newCar.team = team;
readline.question("TC (1/2): ", tc => {
newCar.tc = tc;
readline.close();
console.log(newCar);
});
});
});
});
}
else {
console.log("Invalid choice!\n");
getUserInput(dbData);
}
});
}
else {
console.log("Invalid choice!\n");
getUserInput(dbData);
};
});

node mssql multiple queries in one BEGIN TRANSACTION

Would like to do multiple updates via my API using mssql transactions.
Example:
Shipping Table
Listing Table
User_Notes Table
Customer_Login Table
Push_Notification Table
Which is the right way of doing it?
I was thinking at first of doing it with raw queries.
BEGIN TRANSACTION
CREATE IN SHIPPING
UPDATE IN LISTING
CREATE IN USER_NOTES
UPDATE IN CUSTOMER_LOGIN
CREATE IN PUSH_NOTIFICATION
COMMIT
But want to avoid writing a big raw query like this.
Also can I use mssql Transactions and Queries with (request.query).
const transaction = new sql.Transaction(/* [pool] */)
transaction.begin(err => {
// ... error checks
const request = new sql.Request(transaction)
request.query('create in shipping table', (err, result) => {
// ... error checks
transaction.commit(err => {
// ... error checks
console.log("Transaction committed.")
})
})
request.query('Update in Listing Table', (err, result) => {
// ... error checks
transaction.commit(err => {
// ... error checks
console.log("Transaction committed.")
})
})
and so on...
.
.
.
})

node-sqlite insert fails on not-null constraint, but data are there?

I've got the following code in my nodejs app as part of an expressjs service:
let db = sqlite.open(conf.database, { Promise }).then( (dba) => {
P.all([dba.exec(accesslog_ddl),dba.exec(tokens_ddl)]).then(()=>{
console.log("Database initialized ...");
});
return dba;
});
let upsertToken = function (token, expire, customer) {
return db.then(d=>{
console.log(`${token}, ${expire}, ${customer}`);
return d.exec("insert into tokens (tokenid, name, email, cell, expire) values (?,?,'none','none','never')",
[token,expire]);
});
};
// ... expressjs setup ...
router.post('/tokens',(req,res) => {
tokens.addToken(req.body.token, req.body.expires, req.body.name)
.then(() => {res.status(201).send()})
.catch((e) => {res.status(500).send(e)});
});
The output in the logs is as follows:
bluhbleh, never, fred flintstone
{ [Error: SQLITE_CONSTRAINT: NOT NULL constraint failed: tokens.name] errno: 19, code: 'SQLITE_CONSTRAINT' }
POST /services/tokens 500 20.287 ms - 2
This proves that token, expire, and customer are all present prior to the exec() call, yet the call fails due to a NOT NULL constraint failure.
A few odd things about this code:
I'm using the promisified node-sqlite package.
I'm using a promisified expressjs router.
I really am new to promises (and nodejs generally), and am probably not doing something right.
My full code is here:
https://bitbucket.org/highaltitudearchery/locker/src/master/
You're using exec wrong. The promisified version of Database#exec only takes a single argument, the SQL to execute.

Found error while going to fetch using ripple lib function getTransactions(address,Options)

[MissingLedgerHistoryError(Server is missing ledger history in the specified range)] error found
options.minLedgerVersion = +req.query.minLedgerVersion;
options.maxLedgerVersion = +req.query.maxLedgerVersion;
options.types = ['payment'];
api.connect().then(() => {
/* begin custom code ------------------------------------ */
return api.getTransactions(req.query.address,options)
}).then(transaction => {
console.log("Transactions info ::: ",transaction);
res.status(200).json(formatter.simpleFormat(transaction,true,"success"));
}).catch(err => {
console.log(err);
res.status(500).json(formatter.simpleFormat(null,false,"error"));
});
You'd find your answer in the response returned by the server_info method.
Look for: result/info/complete_ledgers and see if your requesting ledgers are included

Mapping the JSON values to the UI fields in Angular 4

I am trying to do an update operation using Mean Stack with Angular 4. I am new to this technology. For update oprtn I need to map the values to UI form based on id selected to update the record. My data service is fetching record values from MongoDb database in the form of JSON which needs to be updated. However, I am unable to set those parameters to the fields present over the form in the typescript code.
I am using JSON.parse method for implementing it But getting below error.
Error: SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse ()
Typescript code
updateitem(itemid){
let updatedresult;
console.log("toupdateid", itemid);
this.dataService.getItemById(itemid)
.subscribe(
res=> {
this.res =JSON.parse(res);
this.newSession.trainingName =res["TrainingName"],
this.newSession.description = res["Description"];
console.log('newsession', this.newSession);
},
err=> this.apiError = err,
() => {
this.getFormdetails();
}
)
}
dataservice
getItemById(id):Observable<any>{
console.log('idvalue', id);
return this.http.get("http://localhost:3000/getitem"+"/"+ id)
.map(result =>{ this.result = result.json();
console.log('getitembyid' ,result.json())})
.catch((error:any) => Observable.throw('Server Error to get the item'));
}
}
.map(result =>{ this.result = result.json();
console.log('getitembyid' ,result.json())})
Change it to
.map(result => result.json())
And remove the JSON.parse in ts code as now it will return from the service as a JSON object itself
That error occurs when server sends a invalid json. You need to check response of the server.
there are different reasons for that but most likely:
you are sending your request to a wrong endpoint. So instead of json you get a document starting with u and it tries to parse it.
Another one is server sending you a wrong response which is not in JSON format. Try to see if response is turned into a json string on server side.
But since it starts with u its most likely trying to parse an undefined string. I sugest instead of subscribing function you should nest promises like following.
getItemById(id):Observable<any>{
console.log('idvalue', id);
return this.http.get("http://localhost:3000/getitem"+"/"+ id).then(result => {
return result.json();
}) //this will return promise
.catch((error:any) => Observable.throw('Server Error to get the item'));
}
}
and on your updateItem
updateitem(itemid){
let updatedresult;
console.log("toupdateid", itemid);
this.dataService.getItemById(itemid)
.then(
res=> {
this.res =JSON.parse(res);
this.newSession.trainingName =res["TrainingName"],
this.newSession.description = res["Description"];
console.log('newsession', this.newSession);
this.getFormdetails();
}).catch(err => {
this.apiError = err
})
)
}

Resources