url = "https://eth-mainnet.alchemyapi.io/v2/demo"
"method":"eth_blockNumber",
'Content-Type': 'application/json'
response = requests.request("POST", url, headers=headers, data=payload)
res = (json.loads(response.text))
return(int(res["result"],0))
def getCode(contract_address, block_num):
url = "https://eth-mainnet.alchemyapi.io/v2/demo"
"params":[contract_address, block_num],
'Content-Type': 'application/json'
response = requests.request("POST", url, headers=headers, data=payload)
res = (json.loads(response.text))
def getTxReceipt(block_num):
url = "https://eth-mainnet.alchemyapi.io/v2/demo"
"method": "alchemy_getTransactionReceipts",
"blockNumber": hex(block_num)
'Content-Type': 'application/json'
response = requests.request("POST", url, headers=headers, data=payload)
res = (json.loads(response.text))
return(res["result"]["receipts"])
# Returns index of x in arr if present, else -1
def binary_search(arr, low, high, contract_address):
mid = int((high + low)/2)
#print("high: ", high, "mid: ", mid, "low: ", low)
# If element is smaller than mid, then it can only
# be present in left subarray
if getCode(contract_address, hex(mid)) != "0x":
return binary_search(arr, low, mid, contract_address)
# Else the element can only be present in right subarray
elif getCode(contract_address, hex(mid)) == "0x":
return binary_search(arr, mid+1, high, contract_address)
# Element is not present in the array
def find_contract_deployer(contract_address):
arr = list(range(0, currNum))
result_block_num = binary_search(arr, 0, len(arr)-1,contract_address)
receipts = (getTxReceipt(result_block_num))
if ((r["contractAddress"]) == contract_address.lower()):
return(r["from"], result_block_num)
# Find the deployer address of the BAYC contract
print(find_contract_deployer("0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"))