Everybody!
I'd like to get the BNB price from Binance API in solidity.
https://api.binance.com/api/v3/klines?symbol=BNBBUSD&interval=1m&limit=1
I can get candlestick data from the above link.
Is available same data in solidity?
Please help me.
Solidity can't query off-chain resources on its own. But you can use an oracle that will deliver the data to your contract.
A widely-used oracle service is Chainlink. Your contract queries their contract, pays with LINK for the query, and one of the Chanlink providers call your (predefined) callback function with the desired data.
Or you can build a simple oracle service on your own. Your off-chain app listens to specific transactions (from&to a predefined address in a predefined format). When this specific transaction is send, the off-chain app retrieves the off-chain data and sends a transaction (from a connected account) to your contract, passing the data.
Related
I want to get the "entire" ethereum blockchain data, not just from a few sets of smart contracts. By data I mean, transaction details including the generated logs.
I can get real-time data using Infura, but it's pretty much impossible to fetch all the old data, it would simply cost too much because I would simply have to do too many network requests.
I need the old data because I am trying to make an indexed database out of the "append-only" ethereum transaction data so that I can easily query it.
To be more precise, I would like to retrieve all NFT(ERC721, ERC1155) transfer transactions and their logs. So that I can do the following queries and much more: all the NFT owned by a particular wallet, transfer histories of a particular NFT token.
You can do this by
Run your own node
Query data from your node - locally it is fast
For some data, you might need to run the node in archival mode
You can use the same Web3 / JSON-RPC APIs on a local node than you are using on Infura.
Two solutions I have discovered.
Just like #Mikko has mentioned, you can run your own node. And it seemed not be as complex as I have expected. You can search for "geth" and then simply connect this node to your web3 library, just like connecting to Infura.
But I have not tried this and found a much better solution.
Google cloud Bigquery's public data set has all the old ethereum data. Bigquery is Google's data warehouse service, where you can use simple SQL to query your data. It adds new data every day. I have already tested some simple queries from its console and the result was good.
I am planning to fetch all the old data I need from bigquery and store it in my own database and afterwards get real time data from infura. Now that I dont have to fetch all the old data from infura, the price becomes very affordable.
you may check this https://github.com/blockchain-etl/ethereum-etl
It is a Python library for ETL (extract, transform and load) jobs for Ethereum blocks, transactions, ERC20 / ERC721 tokens, transfers, receipts, logs, contracts, and internal transactions.
For example, you may run the cli command
> ethereumetl export_token_transfers --start-block 0 --end-block 500000 \
--provider-uri file://$HOME/Library/Ethereum/geth.ipc --output token_transfers.csv
You may export ERC20 and ERC721 transfers by specific the block number which enable you to query the old data.
Data is also available in Google BigQuery.
is it possible to know for which price user is buying/selling token on transfer function call?
I want to store information on the contract for with user bought/sold tokens on the transfer function.
No, this is not possible, at least in a token contract, because the token contract only "knows" that the user send or approved tokens and that's all that can know, it could be possible in a dex or cex contract
Yes it is possible. this is where oracles comes into play chainlink oracle provide off-chain data like token price feeds in contract in a decentralised way. Here is how you can get token price feed in smart contract in EVM-compatible blockchains
To keep record of price on each transfer extend transfer event to emit the price as well that you fetch from oracle.
Your Flow for modified transfer function will be something like this.
All Checks to ensure (valid transfer + valid oracle call)
Get oracle price of token from oracle and store it in local variable
Transfer
Emit modified event emit Transfer(sender, recipient, amount, price); where price is current price that you got from oracle.
I was reading the "publish" description in the JSON-RPC API and I had a doubt about the possibility of my application. I needed to publish an off-chain item with some metadata information embedded on-chain. For example: "iPhone 2018, New, $400" on the blockchain while {picture.jpg} goes off-chain,
Your best bet here is to publish two stream items simultaneously in a single transaction – one off-chain and one on-chain. You can have the both in the same stream, or in two different streams. These two items will be naturally associated with each other since they will have the same transaction ID. See the publishmulti API (in MultiChain 2.0) for making this easy.
How to get Ethereum internal transaction list / contract transaction list by RPC ?
Contract: 0xa5025faba6e70b84f74e9b1113e5f7f4e7f4859f
How to get the contract address transaction list by RPC ?
enter image description here
What you are trying to do is iterate through the blockchain and check each transaction in each block for a transaction that you are describing. While this will work (with a bit of code), you are better off reading the data from an existing block explorer. By doing it on your own, you will be creating a limited-functionality block explorer, when you should be using other resources.
Take a look at the Etherscan APIs, as they contain all the data you need.
Is it possible to retrieve the service fee charges independent of the SKU like Subscription Fee, FBA Inventory Storage Fee etc. using amazon market API.
I tried the Financial Event API which returns the service fees in the format
<ServiceFeeEvent>
<FeeList>
<FeeComponent>
<FeeType>FBADisposalFee</FeeType>
<FeeAmount>
<CurrencyAmount>-0.15</CurrencyAmount>
<CurrencyCode>USD</CurrencyCode>
</FeeAmount>
</FeeComponent>
</FeeList>
</ServiceFeeEvent>
Which does not contains the data like PostedDate. Is there any oter APIs availabile to get the detailed data of service fee amounts?
In case it's useful for someone else, I figured out an approach that kind of works for me, though it's not ideal.
I'm using the Reports API to download the _GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_ report, which has the fees and a posted-date column. Some of Amazon's documentation about it can be found here: http://docs.developer.amazonservices.com/en_US/reports/Reports_ReportType.html
The disadvantage is that it's only generated once every two weeks. The advantage, compared to the Finances API, is that you get the posting date and the specific transaction that the fee came from.