使用 Web3.py 获取 Pancakeswap Shitcoin 价格

问题描述 投票:0回答:0

下面的代码正确获取了 CAKE 的价格,但在尝试获取 shitcoins 的价格时引发了“web3.exceptions.ContractLogicError:execution reverted”错误。回溯表明这行代码存在问题:“price = routerContract.functions.getAmountsOut(oneToken, [tokenAddress, BUSD]).call()”

我需要在下面的代码中更正什么才能返回此 BSC 令牌的价格:0x0e08093f9f4d695ad12837db11277baf5feb34f2。我怀疑这可能与格式化价格有关。

def calcSell(tokenAddress):
    routerContract = web3.eth.contract(address=routerPCS, abi=panabi)
    oneToken = web3.to_wei(1, 'ether')
    price = routerContract.functions.getAmountsOut(oneToken, [tokenAddress, BUSD]).call()
    normalizedPrice = web3.from_wei(price[1], 'ether')
    return normalizedPrice
    #print(price)
web3 = Web3(Web3.HTTPProvider("https://bsc-dataseed1.binance.org/"))
routerPCS = '0x10ED43C718714eb63d5aA57B78B54704E256024E'
BUSD = '0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56'
spend = web3.to_checksum_address("0x0e08093f9f4d695ad12837db11277baf5feb34f2") 
GALAXY = spend

print(calcSell(GALAXY))
python price pancakeswap web3
© www.soinside.com 2019 - 2024. All rights reserved.