我正在使用 Web3.py,但遇到了一些奇怪的事情。
对于以下代码(使用 Pancake Router V2):
from web3 import Web3
from web3.middleware import geth_poa_middleware
web3 = Web3(Web3.HTTPProvider('https://bsc-dataseed1.binance.org:443'))
web3.middleware_onion.inject(geth_poa_middleware, layer=0)
ABI = {"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"}
CAKE_ROUTER_V2 = web3.toChecksumAddress('0x10ed43c718714eb63d5aa57b78b54704e256024e')
router_contract = web3.eth.contract(address=CAKE_ROUTER_V2, abi=ABI),
WBNB = web3.toChecksumAddress('0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c')
CAKE = web3.toChecksumAddress('0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82')
KONGSHIBA = web3.toChecksumAddress('0x126f5f2a88451d24544f79d11f869116351d46e1')
print(router_contract.functions.getAmountsOut(1, [WBNB, CAKE]).call())
print(router_contract.functions.getAmountsOut(1, [WBNB, KONGSHIBA]).call())
Run Code Online (Sandbox Code Playgroud)
我得到以下信息:
[1, 19]
[1, 160]
Run Code Online (Sandbox Code Playgroud)
WBNB 和 CAKE 有 18 位小数,KONGSHIBA 有 17 位
。CAKE 目前的价值约为 27.7 美元,WBNB 为 545.41291093 美元
,KONGSHIBA 为 0.00000000000000000332 美元。
所以我应该回来:
[1, 19]
[1, 16000000000000000000]
Run Code Online (Sandbox Code Playgroud)
请指教。