Perhaps I missed it in the documentation - what is intended to be in the payload variable in the Go examples?
Like this:
req, _ := http.NewRequest(âGETâ, url, payload)
Perhaps I missed it in the documentation - what is intended to be in the payload variable in the Go examples?
Like this:
req, _ := http.NewRequest(âGETâ, url, payload)
You are referring to a specific endpoint or in general?
There are many endpoints that have it referenced, but in this case Iâm looking at this one
It looks like a typo in documentation as that variable wasnât declared before.
payload is required for the call but I donât know whatâs expected to be in it
Did you try with an empty value?
Yes, that didnât work.
You can check the example with curl and make an equivalent in go assuming that you know go better than the other programming languages form the documentation.
I think whatâs there is the equivalent in Go, itâs just missing some doco. Hmmmm.
This is where Iâm currently stuck - not sure whatâs wrong
package main
import (
âfmtâ
âio/ioutilâ
ânet/httpâ
âstringsâ
)
func main() {
url := "https://deep-index.moralis.io/api/v2/nft/0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0/trades?chain=eth&marketplace=opensea"
payload := getPayload()
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("X-API-Key", "MyAPIKey")
res, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("Error executing request:", err)
return
}
defer func() {
if err := res.Body.Close(); err != nil {
fmt.Println("Error closing response body:", err)
}
}()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("Error reading response body:", err)
return
}
fmt.Println(res)
fmt.Println(string(body))
}
func getPayload() *strings.Reader {
payload := strings.NewReader({"from_block":1,"to_block":9999999999,"limit":500,"cursor":"","disable_total":true}
)
return payload
}
What happens? What doesnât work?
I actually rewrote the function entirely and it works - I am having some issues getting the cursor part to work now