How to get NFT contract creator address
Learn how to get the smart contract deployer address for NFTs, ERC20 tokens, or other on-chain contracts.
A few reasons why you'd want to get a smart contract's deployer address:
  • Verify the provenance of smart contracts deployed on-chain
  • Find the owner/OG deployer of an NFT collection
While this type of query can seem intimidating, developers are able to leverage the power of Alchemy’s Transaction Receipts API with a few Ethereum RPC calls to get in-depth on-chain data.
In this tutorial, we’ll be using a combination of Ethereum RPC methods and Alchemy’s Transaction Receipts API to fetch a smart contract deployer address.

How to find a smart contract deployer address

When searching for the deployer address of a smart contract, we first use binary search to find the origin block number of the contract.
In particular, we use eth_getCode in combination with our searching algorithm to find the exact moment in block history such that a given address stores code. While you can certainly iterate through all blocks from the latest block down to the target block, binary search will speed this process up!
After finding the target block where the contract deployment happened, we can then query alchemy_getTransactionReceipts using the newly found origin block number and filter for our desired transaction information!

How to Get a Smart Contract's Deployer Address

In this tutorial, we make a few different API calls, eth_blockNumber, eth_getCode, & alchemy_getTransactionReceipts. Let's go through the specific requests made.

eth_blockNumber

This API endpoint accepts no parameters! It only returns the most recent block number.
We use this endpoint so that we can get the latest block, constraining our search space from 0 to the latest block. Binary search requires that we have a finite, ordinal list of numbers that we are searching through, and this block range allows us to construct the list.

eth_getCode

  • DATA, address; can be either a smart contract or EOA (externally owned address)
  • QUANTITY|TAG - integer block number
1
params: ['0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D', 12412441]
Copied!
NOTE: The majority of smart contracts will return a non-zero value when eth_getCode is called on it. However, in edge cases, it is possible for contracts to return a storage value of zero which would through an error with the search method presented in this tutorial.

alchemy_getTransactionReceipts

  • blockNumber - the block number you want to get transaction receipts for
1
params: [{"blockNumber": 12412441}]
Copied!

Example: How to Get a Contract's Deployer Address

Python
transaction-receipts-scripts/contract_creation_finder.py at main · alchemyplatform/transaction-receipts-scripts
GitHub
Fetching a Contract's Deployer Address Github Repo

1. Create a file.

In your current directory, create a new file called contract_creation_finder.py using your favorite file browser/code editor.
2. Write script!
Copy and paste in the following code snippet into your new file: contract_creation_finder.py
contract_creation_finder.py
1
import requests
2
import json
3
import time
4
5
def getBlockNum():
6
url = "https://eth-mainnet.alchemyapi.io/v2/demo"
7
8
payload = json.dumps({
9
"jsonrpc":"2.0",
10
"method":"eth_blockNumber",
11
"params":[],
12
"id":0
13
})
14
15
headers = {
16
'Content-Type': 'application/json'
17
}
18
19
response = requests.request("POST", url, headers=headers, data=payload)
20
res = (json.loads(response.text))
21
return(int(res["result"],0))
22
23
def getCode(contract_address, block_num):
24
url = "https://eth-mainnet.alchemyapi.io/v2/demo"
25
26
payload = json.dumps({
27
"jsonrpc":"2.0",
28
"method":"eth_getCode",
29
"params":[contract_address, block_num],
30
"id":0
31
})
32
33
headers = {
34
'Content-Type': 'application/json'
35
}
36
37
response = requests.request("POST", url, headers=headers, data=payload)
38
res = (json.loads(response.text))
39
return(res["result"])
40
41
def getTxReceipt(block_num):
42
url = "https://eth-mainnet.alchemyapi.io/v2/demo"
43
44
payload = json.dumps({
45
"jsonrpc": "2.0",
46
"method": "alchemy_getTransactionReceipts",
47
"params":[
48
{
49
"blockNumber": hex(block_num)
50
}
51
],
52
"id": 1
53
})
54
55
headers = {
56
'Content-Type': 'application/json'
57
}
58
59
response = requests.request("POST", url, headers=headers, data=payload)
60
res = (json.loads(response.text))
61
return(res["result"]["receipts"])
62
63
# Returns index of x in arr if present, else -1
64
def binary_search(arr, low, high, contract_address):
65
66
# Check base case
67
if high >= low:
68
69
mid = int((high + low)/2)
70
#print("===")
71
#print("high: ", high, "mid: ", mid, "low: ", low)
72
73
if (high == low):
74
return low
75
76
# If element is smaller than mid, then it can only
77
# be present in left subarray
78
79
if getCode(contract_address, hex(mid)) != "0x":
80
return binary_search(arr, low, mid, contract_address)
81
82
# Else the element can only be present in right subarray
83
elif getCode(contract_address, hex(mid)) == "0x":
84
return binary_search(arr, mid+1, high, contract_address)
85
86
else:
87
# Element is not present in the array
88
return -1
89
90
def find_contract_deployer(contract_address):
91
92
currNum = getBlockNum()
93
arr = list(range(0, currNum))
94
95
# Function call
96
result_block_num = binary_search(arr, 0, len(arr)-1,contract_address)
97
98
receipts = (getTxReceipt(result_block_num))
99
100
#print(len(receipts))
101
102
for r in receipts:
103
if ((r["contractAddress"]) == contract_address.lower()):
104
return(r["from"], result_block_num)
105
106
# Find the deployer address of the BAYC contract
107
print(find_contract_deployer("0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"))
108
Copied!

3. Run script!

Now, on your command line, you can execute the script by calling:
1
python contract_creation_finder.py
Copied!

Understanding the API Calls & Queried Data

Now that we have made a query and can see the response, let's learn how we handled the returned data via the API calls that we made.

Raw API Response:

Without parsing the response, we have a command-line print-out that gives us the following information:
1
# Binary Search
2
3
high: 14586896 mid: 7293448 low: 0
4
high: 14586896 mid: 10940172 low: 7293449
5
high: 14586896 mid: 12763534 low: 10940173
6
high: 12763534 mid: 11851853 low: 10940173
7
.......................
8
high: 12287511 mid: 12287504 low: 12287498
9
high: 12287511 mid: 12287508 low: 12287505
10
high: 12287508 mid: 12287506 low: 12287505
11
high: 12287508 mid: 12287507 low: 12287507
12
high: 12287507 mid: 12287507 low: 12287507
13
14
# Transaction Hash Filtering
15
16
{
17
"transactionHash":"0x22199329b0aa1aa68902a78e3b32ca327c872fab166c7a2838273de6ad383eba",
18
"blockHash":"0x5b605ffe97e58c657dd3888c014a47fff085f356aeda27de46594b711da29e18",
19
"blockNumber":"0xbb7e13",
20
"contractAddress":"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
21
"cumulativeGasUsed":"0xce97a6",
22
"from":"0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03",
23
"gasUsed":"0x3b6960",
24
"logs":[........],
25
}
26
.........................
27
{
28
"transactionHash":"0x22199329b0aa1aa68902a78e3b32ca327c872fab166c7a2838273de6ad383eba",
29
"blockHash":"0x5b605ffe97e58c657dd3888c014a47fff085f356aeda27de46594b711da29e18",
30
"blockNumber":"0xbb7e13",
31
"contractAddress":"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
32
"cumulativeGasUsed":"0xce97a6",
33
"from":"0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03",
34
"gasUsed":"0x3b6960",
35
"logs":[....],
36
"logsBloom":"0x00000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000008020000000000000000000800000400000000000000000000000000400000800000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000020000800000000000000000000000000000000000000000000000000000000000000",
37
"status":"0x1",
38
"to":"None",
39
"transactionIndex":"0x9b",
40
"type":"0x0"
41
}
42
43
('0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03', 12287507)
Copied!
As you can visually confirm with the print-outs from our script, at each step, we repeatedly divide the search space containing our target block in half until we have narrowed down the possible locations to just a single block number. Our last print statement of high: 12287507 mid: 12287507 low: 12287507 tells us our search converged at block number 12287507

Understanding Transaction Receipts:

As we can see from the script's raw response, we can pull a lot of data out from the Transaction Receipts API. However, we're only interested in the deployer address of our given smart contract.
  • receipts: list of transaction receipts
    • transactionHash: hash of a transaction
    • blockHash: block hash where this transaction was in.
    • blockNumber: block number where this transaction was in
    • contractAddress: contract address a given transaction interacted with
    • cumulativeGasUsed: total amount of gas used by the transaction plus gas used by transactions executed before the current one in the same block
    • effectiveGasPrice: if a tx is made with EIP1559, it is equal to the actual gas price paid; if made using the old standard, it is equal to the transaction’s gasPrice
    • from: address of the transaction sender
    • gasUsed: gas used by this transaction

Filtering Transaction Receipts:

With our queried response saved as a JSON object, we can index through the transfers to find the information useful for us.
  1. 1.
    Loop through all transactions in the block with the smart contract deployal
  2. 2.
    For each receipt, check if the associated contractAddress matches with the smart contract we're searching for
    1. 1.
      If so, break our loop and print out the from address
1
for r in receipts:
2
if (type(r["contractAddress"]) is str):
3
return(r["from"], result_block_num)
Copied!
If you followed along thus far and commented out intermediate print statements, you'll get the following:
1
('0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03', 12287507)
Copied!
And that's it! You can confirm that your query was indeed correct with Etherscan showing that 0xaba7161a7fb69c88e16ed9f455ce62b791ee4d03 is the deployer of the BAYC contract. If you liked this tutorial, give us a tweet @AlchemyPlatform! (Or give the author @crypt0zeke a shoutout!)
Also, join our Discord server to meet other blockchain devs, builders, and entrepreneurs!