algorand / go-algorand-sdk

Algorand Golang SDK
https://pkg.go.dev/github.com/algorand/go-algorand-sdk/v2
MIT License
185 stars 95 forks source link

msgpack decoding error when calling Block method #639

Closed Terence1105 closed 3 months ago

Terence1105 commented 3 months ago

Example code

package main

import (
    "context"
    "fmt"

    "github.com/algorand/go-algorand-sdk/v2/client/v2/algod"
)

func main() {
    ctx := context.Background()

    cli, err := algod.MakeClient("https://api.tatum.io/v3/blockchain/node/algorand-testnet-algod", "")
    if err != nil {
        panic(err)
    }

    node, err := cli.Status().Do(context.Background())
    if err != nil {
        panic(err)
    }

    block, err := cli.Block(node.LastRound).Do(ctx)
    if err != nil {
        panic(err)
    }

    fmt.Println("Block: ", block)
}

Your environment

Branch: v.2.5.0 Go: 1.21 Algo testnet

Steps to reproduce

  1. Please try to run the code

Expected behaviour

Get the correct block info

Actual behaviour

msgpack decode error [pos 1]: only encoded map or array can be decoded into a struct

jasonpaulos commented 3 months ago

Hi @Terence1105, this looks to be an issue with the remote node provider you're using. If you substitute the node URL with https://testnet-api.algonode.cloud, the block is successfully downloaded.

I have not determined exactly why the blocks served by api.tatum.io are different, but I attempted to decode one locally and I did not see a valid msgpack object.

Terence1105 commented 3 months ago

Hi @jasonpaulos ,

Thank you for the quick response and the helpful suggestion. I switched the node URL to https://testnet-api.algonode.cloud as you recommended, and I can confirm that I was able to download the block successfully.

Thanks again!