Skip to content

Instantly share code, notes, and snippets.

@agazso
Created November 13, 2020 10:21
Show Gist options
  • Save agazso/8c52e385037dac1856d861b44b3a1d74 to your computer and use it in GitHub Desktop.
Save agazso/8c52e385037dac1856d861b44b3a1d74 to your computer and use it in GitHub Desktop.
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