Created
November 13, 2020 10:21
-
-
Save agazso/8c52e385037dac1856d861b44b3a1d74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
const apiKey = 'YOUR-ETHERSCAN-API-KEY' | |
const address = '0xb27e3af4eb6e40007b5f74a635b9d5fb6c4887ec' | |
const urlBase = 'https://api-goerli.etherscan.io/api' | |
async function txlist(address) { | |
const url = `${urlBase}?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&sort=asc&apikey=${apiKey}` | |
const response = await axios.get(url) | |
return response.data.result | |
} | |
async function getTransactionByHash(hash) { | |
const url = `${urlBase}?module=proxy&action=eth_getTransactionByHash&txhash=${hash}&apikey=${apiKey}` | |
const response = await axios.get(url) | |
return response.data.result | |
} | |
async function ethAddressToPubKey(address) { | |
const result = await txlist(address) | |
const outgoingTx = result.find(tx => tx.from == address) | |
const txHash = outgoingTx.hash | |
const txData = await getTransactionByHash(txHash) | |
return txData.publicKey | |
} | |
ethAddressToPubKey(address).then(publicKey => console.log(publicKey)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment