简体   繁体   中英

How to get the address of the contract creator

如果我仅知道合同地址和合同接口(ABI),我试图找出是否可以获取合同创建者的地址?

There is no explicit web3.js method for finding the contract creator address. If you wanted to accomplish this with web3.js, you would essentially have to loop through all the previous blocks and transactions subsequently searching for the transaction receipts via web3.eth.getTransactionReceipt . This will return a contractAddress property which can be compared to the contract address you have.

Here is an example utilizing web3.js (v1.0.0-beta.37):

const contractAddress = '0x61a54d8f8a8ec8bf2ae3436ad915034a5b223f5a';

async function getContractCreatorAddress() {
    let currentBlockNum = await web3.eth.getBlockNumber();
    let txFound = false;

    while(currentBlockNum >= 0 && !txFound) {
        const block = await web3.eth.getBlock(currentBlockNum, true);
        const transactions = block.transactions;

        for(let j = 0; j < transactions.length; j++) {
            // We know this is a Contract deployment
            if(!transactions[j].to) {
                const receipt = await web3.eth.getTransactionReceipt(transactions[j].hash);
                if(receipt.contractAddress && receipt.contractAddress.toLowerCase() === contractAddress.toLowerCase()) {
                    txFound = true;
                    console.log(`Contract Creator Address: ${transactions[j].from}`);
                    break;
                }
            }
        }

        currentBlockNum--;
    }
}

getContractCreatorAddress();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM