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.
1 Answers
0
votes
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.