Get the block_num_hint for calling eos.getTransaction(id, blockNumHint)?
When using eos.getTransaction(id, blockNumHint), I need the blockNumHint.
I tested it without, with only 1 above or below and received always bad request error.
Using cleos it is optional.
Is this intended or a bug?
Quoting from the eosio.stackexchange:
In EOSIO, The block_num_hint argument is optional, and it represents the block number where the transaction should be. This can help find the transaction by fetching just one block when not all history is known.
How can I get the block_num_hintIn most cases you won't know the block in which the transaction is, but if you happen to know or have an idea where it may be, you can make some requests with block_num_hint
Using cleos, without a blok_num_hint, it works fine for me; example:
$ cleos -u https://api.eosnewyork.io get transaction af69829823a4807fa18e4e2ee044552922add451e692ce53c3961f258returns a transaction
https://eosio.stackexchange.com/questions/1827/get-the-block-num-hint-for-calling-eos-gettransactionid-blocknumhint/1832#1832
What is the command you ran?
The hint is available:
USAGE
getTransaction - Retrieve a transaction from the blockchain.
PARAMETERS
{
"id": "transaction_id_type",
"block_num_hint": "uint32?"
}
works:
const transactionID =
'd4d95c85db899a0e54328b2f0c2e2062f1d7dc4445d04008836367d1c5448298';
getTransaction = async (id = transactionID, blockNumHint = 9100334) => {
let result = await this.getTransactionP(id, blockNumHint);
console.log('Transaction details: ', result);
return result;
};
getTransactionP = async (id = transactionIDtest, blockNumHint = blockNumHintTest) =>
new Promise(async (resolve, reject) => {
const res = {};
//eos.getScheduledTransactions(json, lowerBound, limit)
eos.getTransaction(id, blockNumHint, (error, info) => (error ? reject(error) : resolve(res)));
});
does not:
getTransaction = async (id = transactionID, blockNumHint = 9100335) => {
let result = await this.getTransactionP(id, blockNumHint);
console.log('Transaction details: ', result);
return result;
};
getTransaction = async (id = transactionID, blockNumHint = 9100333) => {
let result = await this.getTransactionP(id, blockNumHint);
console.log('Transaction details: ', result);
return result;
};
getTransaction = async (id = transactionID) => {
let result = await this.getTransactionP(id);
console.log('Transaction details: ', result);
return result;
};
Is this normal?
I'm not following your examples.. there is a lot of extra code in there..
simplified:
works:
eos.getTransaction(id, rightBlockNumHint, (error, info) => (error ? reject(error) : resolve(res)));
does not:
const wrongBlockNumHint = rightBlockNumHint - 1;
eos.getTransaction(id, wrongBlockNumHint, (error, info) => (error ? reject(error) : resolve(res)));
also without BlockNumHint it doesn't work:
eos.getTransaction(id, (error, info) => (error ? reject(error) : resolve(res)));
I assumed the blockNumHint is just a hint and not even obligatory. Is this normal?
It looks like you'll need blockNumHint = 0 as a place holder, they are using 0 in the back end to show this is not being set.
eos.getTransaction(id, 0, (error, info) => (error ? reject(error) : resolve(res)));
Optional parameters are uncommon and I'm not sure they would alway be last. I'll keep an eye on this though. Thanks for pointing it out. I'll add some docs.
interesting! I tried it with 0, works! Then again without and with a wrong blocknumhint and suddenly it works as well. Not sure what changed. In case it appears again, I take a deeper look and and keep you updated