0

I am trying to send Transaction using Zapper which swaps MATIC to USDC.

Here's my script which worked few times but later started throwing the error

from web3 import Web3
import json
import requests

infura_url = "https://polygon-mainnet.g.alchemy.com/v2/{my_key}"

w3 = Web3(Web3.HTTPProvider(infura_url))

print(w3.isConnected())

private_key = 'my_pvt_key'
nonce = w3.eth.getTransactionCount('0x4D4750538C58937474a4A0Ac2a4448a207536e8B')
account_2 = '0xdef1c0ded9bec7f1a1670819833240f027b25eff'
account_2 = w3.toChecksumAddress(account_2)

url = 'https://api.zapper.fi/v1/exchange/quote?gasPrice=10000000000&sellTokenAddress=0x0000000000000000000000000000000000000000&buyTokenAddress=0x2791bca1f2de4661ed88a30c99a7a9449aa84174&sellAmount=1000000000000000000&network=polygon&api_key=96e0cc51-a62e-42ca-acee-910ea7d2a241'
r = requests.get(url)
print(r.status_code)

resp_dict  = r.json()

tx = {
    "nonce": nonce,
    "data" : resp_dict['data'],
    "to": account_2,
    "gas": int(resp_dict['estimatedGas']),
    'gasPrice': int(resp_dict['gasPrice']),
    'chainId' : 137,
    "value":1000000000000000000,
}
signed_tx = w3.eth.account.signTransaction(tx, private_key)

tx_hash = w3.eth.sendRawTransaction(signed_tx.rawTransaction)

print(w3.toHex(tx_hash))

Here's the Transaction Hash : https://polygonscan.com/tx/0x5d50a554f1e01686c50d045f5f2adf36a369c1cbdf31c94c21bce1c0cf44fc91

Which produces the error : A Status code indicating if the top-level call succeeded or failed (applicable for Post BYZANTIUM blocks only)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.