I'm trying to use 0x protocol on goerli and gathering the transaction data from their json response, which contains all the necessary information needed for the swap. Is it possible to successfully send this transaction in this manner without using contract.functions.TransformERC20.buildTransaction()??
I've tried messing around with the data types for the transaction inputs but my transactions keep reverting.
testurl = "https://goerli.api.0x.org/swap/v1/quote?buyToken=0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984&sellToken=0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6&sellAmount=100000000000000"
mResponse = requests.get(url=testurl)
_mdata = mResponse.json()
nonce = web3.eth.get_transaction_count(ADDRESS)
gas = int(_mdata["gas"])
_data = _mdata["data"]
tx_create = {
"nonce": nonce,
'maxFeePerGas': web3.toWei(250, 'gwei'),
'maxPriorityFeePerGas': web3.toWei(2, 'gwei'),
"gas": gas,
"to": web3.toChecksumAddress(_mdata[to]),
"value": 0,
"data": _data,
"chainId": 5,
}
signed_txn = web3.eth.account.signTransaction(tx_create, private_key=PRIVATE_KEY)
tx_hash = web3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_receipt = web3.eth.wait_for_transaction_receipt(tx_hash)
Here is the request response
{
'chainId': 5,
'price': '1.42178433130197',
'guaranteedPrice': '1.40756648798895',
'estimatedPriceImpact': '0',
'to':
'0xf91bb752490473b8342a3e964e855b9f9a2a668e',
'data': '0x415565b0000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d60000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000008004760d2aaf00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003e000000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d60000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000005af3107a40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000025375736869537761700000000000000000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000008004760d2aaf000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b4799750600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d60000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d6000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd000000000000000000000000100000000000000000000000000000000000001100000000000000000000000000000000000000000000001963945d63637134cd',
'value': '0',
'gas': '111000',
'estimatedGas': '111000',
'gasPrice': '110000',
'protocolFee': '0',
'minimumProtocolFee': '0',
'buyTokenAddress': '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
'sellTokenAddress': '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
'buyAmount': '142178433130197',
'sellAmount': '100000000000000',
'sources': [{'name': '0x', 'proportion': '0'}, {'name': 'SushiSwap', 'proportion': '1'}, {'name': 'Uniswap', 'proportion': '0'}, {'name': 'Uniswap_V2', 'proportion': '0'}, {'name': 'Uniswap_V3', 'proportion': '0'}, {'name': 'MultiHop', 'proportion': '0'}],
'orders': [{'type': 0, 'source': 'SushiSwap', 'makerToken': '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', 'takerToken': '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', 'makerAmount': '142178433130197', 'takerAmount': '100000000000000', 'fillData': {'tokenAddressPath': ['0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'], 'router': '0x1b02da8cb0d097eb8d57a175b88c7d8b47997506'}, 'fill': {'input': '100000000000000', 'output': '142178433130197', 'adjustedOutput': '142164461473503', 'gas': 90000}, 'sourcePathId': '0x890b25b4cab90e4789caa533096dbf7bb521717fbea17ff3928af2923b7331b3'}],
'allowanceTarget': '0xf91bb752490473b8342a3e964e855b9f9a2a668e',
'decodedUniqueId': '1963945d63-1668363469',
'sellTokenToEthRate': '1',
'buyTokenToEthRate': '1.411278453943217396',
'expectedSlippage': None
}
Here is the transaction receipt
{
'blockHash': HexBytes('0xcdbd801ece7c4046bbd0685026d2d7e4c4501b5e70eb5442d3313f7994b15ba4'),
'blockNumber': 8043516,
'contractAddress': None,
'cumulativeGasUsed': 19623461,
'effectiveGasPrice': 5292860000,
'gasUsed': 109792,
'logs': [],
'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),
'status': 0,
'to': '0xF91bB752490473B8342a3E964E855b9f9a2A668e',
'transactionHash': HexBytes('0x37487c3085503283681de66034962bfe3d0583ab1059f30f71363188b6a8eb46'),
'transactionIndex': 115,
'type': '0x0'
}