Decoding input data from BSC transaction causes OverflowError: Python int too large to convert to C ssize_t

41 Views Asked by At
import requests
from web3 import Web3
from eth_abi import decode

def get_transaction_input_data(tx_hash):
    apikey = "xxx"
    url = f"https://api.bscscan.com/api?module=proxy&action=eth_getTransactionByHash&txhash={tx_hash}&apikey={apikey}"
    response = requests.get(url)
    transaction = response.json().get('result', {})
    
    return transaction.get('input', '')

input_data = get_transaction_input_data("0xcbf70aa81c21cff3ae91fc95e0ec5b473fbb4d046e898b02cf93830e98fdeb7e")
print(f"Input Data: {input_data}")

w3 = Web3(Web3.HTTPProvider('https://bsc-dataseed1.binance.org/'))

types = ['address[]', 'uint256[]']
decoded_data = decode(types, bytes.fromhex(input_data[2:]))

recipients = decoded_data[0]
amounts = decoded_data[1]

print("Recipients: ", recipients)
print("Amounts: ", amounts)

causes

  File "D:\python\bsc\query.py", line 23, in <module>
    decoded_data = decode(types, bytes.fromhex(input_data[2:]))
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\codec.py", line 161, in decode
    return decoder(stream)
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 129, in __call__
    return self.decode(stream)
  File "D:\python\bsc\venv\lib\site-packages\eth_utils\functional.py", line 47, in inner
    return callback(fn(*args, **kwargs))
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 175, in decode
    yield decoder(stream)
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 129, in __call__
    return self.decode(stream)
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 146, in decode
    stream.push_frame(start_pos)
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 95, in push_frame
    self.seek_in_frame(0)
  File "D:\python\bsc\venv\lib\site-packages\eth_abi\decoding.py", line 84, in seek_in_frame
    self.seek(self._total_offset + pos, *args, **kwargs)
OverflowError: Python int too large to convert to C ssize_t

You can see the input data at https://bscscan.com/tx/0xcbf70aa81c21cff3ae91fc95e0ec5b473fbb4d046e898b02cf93830e98fdeb7e in the more details section

any ideas what to do about this?

1

There are 1 best solutions below

0
jdoe On

The input data is sent to a smart contract function to deliver an airdrop. The data contains the recipients addresses and the amount to be airdropped

I wrote this code to extract the data myself

def process_input_data(data):
    recipients = []
    amounts = []
    #this function find the recipient addresses and the amounts airdropped
    #cut off the first 10 characters
    data = data[10:]
    #split data into 64bit sections
    sections = [data[i:i+64] for i in range(0, len(data), 64)]
    #extract number of recipients
    number_of_recipients = int(sections[2],16)
    #cut off the first 3 items
    sections = sections[3:]
    #cut out the separator between recipients and amounts
    del sections[number_of_recipients]

    recipients = sections[:number_of_recipients]
    for i in range(number_of_recipients):
        #recipients[i] = recipients[i][24:].lstrip("0")
        recipients[i] = recipients[i][-40:]
    amounts = sections[number_of_recipients:]

    #appends 0x to the addresses to create wallet addresses
    recipients_with_ox = ["0x" + code for code in recipients]
    #converts 16bit hexadecimal to integer, divide by the individual units of the chain. 
    amounts_decimal = [(int(item,16)) / 10 ** 18 for item in amounts]

    return list(zip(recipients_with_ox, amounts_decimal))

the types are ['address[]', 'uint256[]'] these are a wallet address without the 0x and the amount of tokens