Как дела?
Я пытаюсь точно сделать ввод обмену, и я генерирую хэш и тратил газ, но токены не поменяются. < /p>
< P> Это хэш, который был сгенерирован, но токены не поменялись:
0x29972068D98F7C5C1D8AB54C3B1F48CADC0F4000F94BA9DC01B6DC6192593346 < /p>
Это функция, которая сгенерировала ее: < /p>
def uniswap_swap_function(web3, contract_router, wallet_address_metamask, wallet_private_key_metamask, swap, slippage=0.5):
print(swap)
quantity_in = float(swap['quantity_in'])
token_address_in = web3.to_checksum_address(swap['token_address_in'])
token_address_out = web3.to_checksum_address(swap['token_address_out'])
decimals_token0 = int(swap['decimals_in']) # Decimais do token de entrada
decimals_token1 = int(swap['decimals_out']) # Decimais do token de saída
# Definir valores da troca com base nos decimais do token de entrada
amount_in_wei = int(float(swap['quantity_in']) * (10 ** decimals_token0))
# Instanciando o contrato do Uniswap V3 Router
uniswap_router = web3.eth.contract(
address=web3.to_checksum_address("0xE592427A0AEce92De3Edee1F18E0157C05861564"),
abi=[
{
"inputs": [
{
"components": [
{"internalType": "address", "name": "tokenIn", "type": "address"},
{"internalType": "address", "name": "tokenOut", "type": "address"},
{"internalType": "uint24", "name": "fee", "type": "uint24"},
{"internalType": "address", "name": "recipient", "type": "address"},
{"internalType": "uint256", "name": "deadline", "type": "uint256"},
{"internalType": "uint256", "name": "amountIn", "type": "uint256"},
{"internalType": "uint256", "name": "amountOutMinimum", "type": "uint256"},
{"internalType": "uint160", "name": "sqrtPriceLimitX96", "type": "uint160"}
],
"internalType": "struct ISwapRouter.ExactInputSingleParams",
"name": "params",
"type": "tuple"
}
],
"name": "exactInputSingle",
"outputs": [
{"internalType": "uint256", "name": "amountOut", "type": "uint256"}
],
"stateMutability": "payable",
"type": "function"
}
]
)
# Definição do pool de taxas da Uniswap V3 (3000 = 0.3%, 500 = 0.05%)
pool_fee = 3000 # Ajuste conforme necessário
# Calculando o valor mínimo esperado com base no slippage
expected_out = float(swap['quantity_out']) * (10 ** decimals_token1)
amount_out_min = int(expected_out * (1 - slippage / 100))
# Definição do deadline (tempo limite para a transação)
deadline = int(time.time()) + 60 # 1 minuto
# Parâmetros do swap no Uniswap V3
params = (
token_address_in,
token_address_out,
pool_fee,
wallet_address_metamask,
deadline,
amount_in_wei,
amount_out_min,
0
)
# Construção da transação
txn = uniswap_router.functions.exactInputSingle(params).build_transaction({
'from': wallet_address_metamask,
'gas': 250000,
'gasPrice': web3.eth.gas_price,
'nonce': web3.eth.get_transaction_count(wallet_address_metamask),
})
# Assinar a transação
signed_txn = web3.eth.account.sign_transaction(txn, wallet_private_key_metamask)
# Enviar a transação
txn_hash = web3.eth.send_raw_transaction(signed_txn.raw_transaction)
# Esperar a transação ser confirmada
txn_receipt = web3.eth.wait_for_transaction_receipt(txn_hash)
print(f'Transação confirmada com hash: {txn_receipt.transactionHash.hex()}')
return txn_receipt.transactionHash.hex()
< /code>
У кого -нибудь есть какое -либо представление о том, что может быть неправильно? Я застрял некоторое время, и все токены одобрены.
Подробнее здесь: https://stackoverflow.com/questions/794 ... blockchain
Токены не сбиты в Uniswap (Blockchain Web3) ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
«Web3.py: 'buildTransaction' не работает для функции swapExactETHForTokens Uniswap V2»
Anonymous » » в форуме Python - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-