I'm new to blockchain. My question is how can I get binance blockchain info without explorers (get block by number, get transaction by hash)? ETH has tools such as geth
or web3
where I can simply make a eth.getTransaction(hash)
or eth.getBlock(number)
requests and get any transaction/block info. Binance has API but as far as I understand you can get info only for your wallet. Are there any official tools for binance blockchain? Where have explorers got binance blockchain info?
Asked
Active
Viewed 1,347 times
0

airled
- 177
- 3
- 15
-
Binance blockchain? I'm afraid your question doesn't make a lot of sense. Are you trying to get market information from Binance (e.g. order book, price, etc.), or get information regarding the BNB blockchain? To clarify in case my question doesn't make sense: Binance is an _exchange_ that has its own cryptocurrency for fee purposes called _BNB_. – felipe Mar 09 '21 at 06:40
-
Thanks for your reply. `get information regarding the BNB blockchain?`. Right. For example, I have a transaction hash `0xcda69cec49c4bb3085b9af5a1f8a62fd83a781c65c03a2fd918214f404263bd3`. Is there any way to retrieve information about this transaction without bscscan or other indexers? – airled Mar 09 '21 at 06:59
-
1You can probably use something like [`python-binance-chain`](https://github.com/sammchardy/python-binance-chain). – felipe Mar 09 '21 at 07:02
-
Oh. So they have separate APIs for account and blockchain. Make sense now. Thank you so much! – airled Mar 09 '21 at 07:10
-
The linked project is an *unofficial* wrapper over the API that Binance exposes (just so you are aware). :) – felipe Mar 09 '21 at 07:13
-
I will use official api instead. I just have not seen that binance has two separate apis. – airled Mar 09 '21 at 07:20
-
The Binance Smart Chain uses the same apis as Ethereum - Remix, Metamask and web3 all work with it. And there's an equivalent of [etherscan](https://bscscan.com/) – StuartLC Jun 28 '21 at 21:59
1 Answers
1
You can use most of the same tools, such as web3. Just use the binance as the provider (JS):
// mainnet
const web3 = new Web3('https://bsc-dataseed1.binance.org:443');
// testnet
const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545');
In python you have to add middlewear:
from web3 import Web3
from web3.middleware import geth_poa_middleware
web3 = Web3(Web3.WebsocketProvider(
"wss://bsc-ws-node.nariox.org:443",
websocket_timeout=60,
))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)

Branko B
- 94
- 4