Skip to content

Instantly share code, notes, and snippets.

@dcb9
Last active March 8, 2018 02:31
Show Gist options
  • Save dcb9/df0f846c825933db1c5d6622df944945 to your computer and use it in GitHub Desktop.
Save dcb9/df0f846c825933db1c5d6622df944945 to your computer and use it in GitHub Desktop.
func ethGetLogs(contractAddress string, hexOfEvent string) {
generateZeros := func() string {
str := ""
for i := 0; i < 24; i++ {
str += "0"
}
return str
}
ethAddress = fmt.Sprintf("0x%s%s", generateZeros(), ethAddress[2:])
// eth_getLogs API: https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
// Topics see https://ethereum.stackexchange.com/questions/12553/understanding-logs-and-log-blooms
requestJsonText := fmt.Sprintf(
`{"jsonrpc":"2.0","method":"eth_getLogs"`+
`,"params":[{"fromBlock": "0x1", "topics":["%s"], "address": "%s"}]`+
`, "id": 1}`,
hexOfUploadProofFunc,
contractAddress,
)
body := strings.NewReader(requestJsonText)
req, err := http.NewRequest("POST", "https://rinkeby.infura.io", body)
if err != nil {
fmt.Println(err)
return
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(bytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment