6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python web3 で Pancakeswap で流動性ペアの残高を取得するメモ

Posted at

BSC(Binance Smart Chain): 基本 ethereum のクローン
Pancakeswap: 基本 uniswap のクローン

のため,

Python web3 で Uniswap の流動性ペアの残高を取得するメモ
https://qiita.com/syoyo/items/d4db214903bd0105247c

のやり方を周到できます.

pancakeswap API もあるようですが, どうもうまく動いていなかったりしてメンテされていない雰囲気あります.

ブロックチェーンノードの用意

BSC の場合は RPC endpoint が用意されています. ありがとうございます.

ただ, クエリできるのは 1 時間前くらいまでの block のようです.

調べる

import json

from web3 import Web3,HTTPProvider

web3 = Web3(HTTPProvider('https://bsc-dataseed.binance.org/'))
blockNumber=web3.eth.blockNumber
print(blockNumber)

addr_wbnb_usdt = Web3.toChecksumAddress('0x20bcc3b8a0091ddac2d0bc30f68e6cbb97de59cd') # Pancakeswap WBNB/USDT pair

abi_wbnb_usdt = json.loads(open('abi.json').read())

contract = web3.eth.contract(address=addr_wbnb_usdt, abi=abi_wbnb_usdt)
print("decimals", contract.functions.decimals().call())
print("totalSupply", contract.functions.totalSupply().call())
print("token0 addr", contract.functions.token0().call())
print("token1 addr", contract.functions.token1().call())
print("reserves(token0, token1, blocktime): ", contract.functions.getReserves().call())

でいけました.

TODO

  • ローカルで geth(BSC node)ノードを建てて特定のブロックのときの情報を取得できるか調べる
6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?