简体   繁体   English

检查令牌是否已被批准python

[英]Checking if Token is already approved python

I have this code for checking if a token is already approved.我有这个代码来检查令牌是否已经被批准。 The problem is, i get everythime 0 even if i put in an approved token.问题是,即使我输入了已批准的令牌,我也会得到每一次 0。 Do you know what im doing wrong?你知道我做错了什么吗? Thank you in advance先感谢您

import json
import sys
from web3 import Web3

bsc = "https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))
print(web3.isConnected())


"0x3c7eeddcff188a8c36f1cac1b62958c6e0c27dea"  # G2 already approved
"0xcc5667333f5e997ac9f0c26d41b7dda65b2b675a"  # GloryDoge not approved

contract = "0x3c7eeddcff188a8c36f1cac1b62958c6e0c27dea"  # Contract
contract = web3.toChecksumAddress(contract)
abi = [
    {
        "constant": True,
        "inputs": [
            {"name": "_owner", "type": "address"},
            {"name": "_spender", "type": "address"},
        ],
        "name": "allowance",
        "outputs": [{"name": "", "type": "uint256"}],
        "payable": False,
        "stateMutability": "view",
        "type": "function",
    },
]
contract = web3.eth.contract(address=contract, abi=abi)

_owner = web3.toChecksumAddress(MYADRESS)
_spender = web3.toChecksumAddress(
    "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"
)  # WBNB

x = contract.functions.allowance(_owner, _spender).call()

print(x)

Your code works fine!你的代码工作正常!

Insead of filling in the wbnb token address for _spender, you should give the address of the thing you gave the allowance to.除了填写_spender的wbnb代币地址之外,您还应该提供您给予津贴的事物的地址。 For instance, the pancake router address "0x10ED43C718714eb63d5aA57B78B54704E256024E".例如,煎饼路由器地址“0x10ED43C718714eb63d5aA57B78B54704E256024E”。

You can check which address you gave allowance to by looking at the approve transaction in bscscan.com您可以通过查看 bscscan.com 中的批准交易来检查您给予的地址

Click on "click to see more", and click on "Decode Input Data".点击“点击查看更多”,然后点击“解码输入数据”。

You will see the spender address that you approved.您将看到您批准的付款人地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM