So verwenden Sie die SWAPEXACTETHFORTOKENS -Funktion in einem Web3py richtigPython

Python-Programme
Anonymous
 So verwenden Sie die SWAPEXACTETHFORTOKENS -Funktion in einem Web3py richtig

Post by Anonymous »

Ich versuche, die Funktion SWAPEXACTETHFORTOKEN mit Pancake Router V2 zu verwenden. Hier ist mein Code: < /p>

Code: Select all

#!/usr/bin/env python3
import time
from web3 import Web3

bsc = "https://data-seed-prebsc-1-s1.binance.org:8545/"
web3 = Web3(Web3.HTTPProvider(bsc))
print("Is web3 connected? ", web3.is_connected())

wallet_address = ""
private_key = ""
nonce = web3.eth.get_transaction_count(wallet_address)

pancake_router_address = "0x6725F303b657a9451d8BA641348b6761A6CC7a17"
pancake_router_ABI = [] # I've got the abi from testnetbscscan and to make it short would not past it here.
contract = web3.eth.contract(address = pancake_router_address, abi = pancake_router_ABI)

WBNB_address = web3.to_checksum_address("0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd")
cake2_address = web3.to_checksum_address("0x8d008B313C1d6C7fE2982F62d32Da7507cF43551")

pancakeswap2_txn = contract.functions.swapExactETHForTokens(
0, # The minimum destination token you want to have, set 0 if you don't care
[WBNB_address, cake2_address],
wallet_address,
(int(time.time()) + 1000000) # 1000000 seconds later

).build_transaction({
'from': wallet_address,
'value': web3.to_wei(0.001,'ether'),
'gas': 250000,
'gasPrice': web3.to_wei('5','gwei'),
'nonce': nonce,
})

signed_txn = web3.eth.account.sign_transaction(pancakeswap2_txn, private_key = private_key)
tx_token = web3.eth.send_raw_transaction(signed_txn.raw_transaction)
print('Transaction hex is: ', web3.to_hex(tx_token))

< /code>
Ich habe verschiedene Pfannkuchen -Router -Adressen verwendet (alle auf testNet), jeder hat ein Problem, z. B. für
0xd9C500DfF816a1Da21A48A732d3498Bf09dc9AEB< /code>
,
0x8d008B313C1d6C7fE2982F62d32Da7507cF43551< /code>
und
0x6725F303b657a9451d8BA641348b6761A6CC7a17
Ich erhalte den Fehler:

Code: Select all

web3.exceptions.ABIFunctionNotFound:
("The function 'swapExactETHForTokens' was not found in this ", "contract's abi.")
und für 0x10ed43c718714eb63d5aa57b78b54704e256024e zeigt diesen Fehler nicht an, aber die Transaktion schlägt mit der Nachricht fehlWarning! Error encountered during contract execution [execution reverted]
< /code>
Weiß jemand, was in meinem Code los ist? Vielen Dank im Voraus! < /P>
p.s. Meine Frage ähnelt dieser und diese Frage habe ich die angegebenen Antworten in Betracht gezogen, aber kein Glück.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post