How to get the minimum gas price on RSK with web3.js? - rpc

I'm using web3.js to get the minimum gas price, but the following is not working:
web3.eth.getBlock('latest').minimumGasPrice
How can I do this?

You can do this using web3.js like so:
const block = await web3.eth.getBlock('latest');
const minimumGasPrice = block.minimumGasPrice;
Note that getBlock() involves a network request,
and therefore needs an await.
Your question only asked for a way to do this in Javascript,
but if you want to do the equivalent using terminal commands,
in case you have not done so yet,
check out the answer on this similar question:
How to calculate what gas price to use for transactions on RSK?
Note: If you're coming from Ethereum development,
the minimumGasPrice field in this RPC response is RSK-only -
do not expect the same from Ethereum.

Related

Google Cloud Vision API : OCR text detection giving inaccurate result- Node JS

I have used the below code to perform text detection on the image.
const client = await new vision.ImageAnnotatorClient({ credentials });
const [result] = await client.textDetection(path);
console.log(result.textAnnotations);
the intended result is BBTPB9999Q but
the program output is BBTPB9999C
Is there any way to improve the accuracy?
From my experience the quality of the pictures matters. So I think improving quality of analyzed image is only way to improve results of detection when it comes to descriptions similar to your example, like serial numbers etc. Once I had an idea to try to convert images before, ex. make them monochrome, however I never got test results worth implementing. You may try this...
At the moment, in Google Cloud Vision, only way to improve the the result for the same picture is to Specify the language, however this will work only when you want to detect text in already known language.

How to set Stop-Limit (STOP_LOSS_LIMIT and/or TAKE_PROFIT_LIMIT) orders in Binance API on spot trading?

I am using the python-binance API wrapper.
After successfully sending a 'normal' MARKET order, I want to send in a STOP_LOSS_LIMIT order. If I'm not mistaken this is a subtype of Stop-Limit orders. This is what they are called in the Binance UI on the app.
Anyway, this is my code for the STOP_LOSS_LIMIT order:
order2 = client.create_order(
symbol='BTCUSDT',
side=SIDE_SELL,
type=ORDER_TYPE_STOP_LOSS_LIMIT,
TimeInForce=TIME_IN_FORCE_GTC,
stopPrice='33000',
price = '30000'
)
I get the following response:
Not all sent parameters were read; read '7' parameter(s) but was sent '8'.
Obviously there is something fundamentally wrong with the code. Can someone provide me with an example for this type of orders. What are the necessary parameters and what do they do. Please do not link me the official documentation. Sadly, there are no examples for these types.
Seems like what I was trying to achieve is not possible with Spot trading. Once I switched to Futures, it all worked out.
This is how I set the leverage to 1:
client.futures_change_leverage(symbol='BNBUSDT', leverage=1)
I conclude that Stop Loss/Take Profit orders do not work with Spot trading, either by design (which actually makes sense), or because of some bugs.
Anyway, if anyone ever hits the same wall, this is how to set a stop loss order on existing Futures (buy) orders in python-binance
FuturesStopLoss =client.futures_create_order(
symbol='BNBUSDT',
type='STOP_MARKET',
side='SELL',
stopPrice=220,
closePosition=True
)
Changing side to BUY sets a stop loss order on existing sell orders.
P.S. Achieving the same with Spot trading is most likely possible by using Websocket streams and executing Market orders when desired prices are reached. However I did not want to go with that route.
By API you can make it with this structure
StopLoss
API POST https://fapi.binance.com/fapi/v1/order
{
"side": "BUY",
"stopPrice": 40100,
"symbol": "BTCUSDT"
}

Stripe: what is the exact functionality of transfer_group?

I am familiar with the documentation on Stripe's website about the transfer_group property here: Transfer Options. However, I find this documentation rather limited and I'm still not sure what it does exactly.
One of the things that I'd expect to happen, is that the charge and associated transfer(s) are somehow grouped together on the Stripe Dashboard. But this appears to not be the case.
My question thus is, what does the transfer_group property do exactly and why would one use it?
EDIT:
I found some use for it now. It can be used in the following way:
const transfers = await stripe.transfers.list({
transfer_group: bookingId
})
This returns all the transfers associated with that transfer_group. Their id's can then be used to create transfer_reversals for example.
Note that the reason I'm not considering this finding as an answer, is because there must be more to it to this (I think).
It associates Charges with Transfers for use in Separate Charges and Transfers.

In bot rewards (discord.py) by voting on top.gg / discordbotlist

When a user votes for my bot on either of the sites, it sends them a DM and I want it to do other things too but for the sake of simplicity can we use a print statement to be triggered once the user votes? is this going to be done using webhooks? I'm totally new to those.
Please give me an example code of how it could be done!
top.gg uses their own API, a full reference can be found here: https://top.gg/api/docs#pylib
You would first need to install their module which can be done with pip install dblpy
In their documentation, it shows many examples of usage and how you can implement them in your code. Simply all it does is, runs a task loop, waiting for a user to upvote, and within your code you can simply do what ever you want with the reward. As well as many other usages they provide, but hope this helps.

Way to enter amount of products to purchase?

Do I have to do this server side with a custom payment button instead of their (beautiful) default one? Or can I just do some logic with the javascript (price*amount) or will it not work with their custom token thingy they generate? I'm using their Java api with Google Appengine, if that makes a difference.
To add to the other posts, here's a concrete example of how I'm doing it.
On the 'pay now' page with the default button, pass in the amount. One way I'm doing this is from a form on a previous page.
Parse this amount, e.g.
<?php
...
$data_amount = $_POST['data_amount'];
...
?>
And then use this amount as a value in the JS script which actually process the charge
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
...
data-amount="<?php echo $data_amount; ?>"
...
</script>
Good luck!
The quantity and any other information about the items being purchased are irrelevant to the payment gateway, in this case, stripe. All that matters is the payment method (e.g. "visa card ending in 1234"), the amount, the currency and the customer.
You don't have to use the stripe provided checkout methods, you can write your own. The stripe examples are extensive and include Java code, though really the concepts are harder than the code itself (and the concepts aren't that hard). The token represents the payment method/customer and has nothing to do with the amount being charged.
You can do whatever you like to implement the product / quantity / price calculations. The Stripe API simply expects your server-side to make a "charge" passing the card (or customer) token, and supplying an amount and a currency. (There are a bunch of optional parameters too ...)
The "token thingy" does not contain an information about the payment itself.
I've not attempted to use Stripe myself. The above is based on a cursory (10 minute) reading of the documentation. But there are copious examples that you can find via the Stripe "Documentation" menu, including (Java) examples of what you need to do on the server side.
As the other folks have mentioned, the token doesn't contain quantity/charge amount info. The charge amount goes into the charge object.
Now, as far as additional info, particularly if you're coming from the classic PayPal world where you have quantities and so forth, or even if not but your purpose requires the back-end to know the extra detail, most (but not all) Stripe objects allow you to store key-value pairs in the optional 'metadata'.
If you're rolling up a cost (particularly if you're doing tax or other computations to get the total) you'll probably want to stuff the essentials (quantity, unit price, tax, itemized list, etc) into that block to be able to sanity-check and/or extract the details later on in the processing flow.
The Stripe docs are quite well done; click 'Java' at the top of the example column and you'll get cut-and-paste examples (for the most part).

Resources