Repository navigation
Expand file tree
/
Copy pathcheck_approval.py
More file actions
60 lines (49 loc) · 1.68 KB
/
Copy pathcheck_approval.py
File metadata and controls
60 lines (49 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Check if relayer is approved for token spending
"""
from web3 import Web3
import os
# BSC Mainnet
RPC_URL = "https://bsc-dataseed1.binance.org"
w3 = Web3(Web3.HTTPProvider(RPC_URL))
# Addresses
USD1_TOKEN = "0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d"
RELAYER = "0xE1C2830d5DDd6B49E9c46EbE03a98Cb44CD8eA5a"
# ERC-20 ABI (minimal)
ERC20_ABI = [
{
"constant": True,
"inputs": [
{"name": "owner", "type": "address"},
{"name": "spender", "type": "address"}
],
"name": "allowance",
"outputs": [{"name": "", "type": "uint256"}],
"type": "function"
}
]
def check_approval(wallet_address: str, token_address: str = USD1_TOKEN, spender: str = RELAYER):
"""Check if spender is approved to spend tokens from wallet"""
token = w3.eth.contract(address=Web3.to_checksum_address(token_address), abi=ERC20_ABI)
allowance = token.functions.allowance(
Web3.to_checksum_address(wallet_address),
Web3.to_checksum_address(spender)
).call()
print(f"Wallet: {wallet_address}")
print(f"Token: {token_address} (USD1)")
print(f"Spender: {spender} (B402 Relayer)")
print(f"Allowance: {allowance}")
if allowance > 0:
print(f"✅ Approved! Can spend up to {allowance / 10**18:.2f} USD1")
return True
else:
print("❌ Not approved. Need to approve relayer first.")
return False
if __name__ == "__main__":
private_key = os.environ.get("PRIVATE_KEY")
if not private_key:
print("Set PRIVATE_KEY environment variable")
exit(1)
from eth_account import Account
account = Account.from_key(private_key)
check_approval(account.address)