Skip to content

Commit

Permalink
chore(docs): fix example rpcclient.NewHTTPClient returning variables (#…
Browse files Browse the repository at this point in the history
…2352)

In the [how to connect a Go app to
Gno.land](https://docs.gno.land/how-to-guides/connect-from-go) tutorial
I got an error when I tried to run this line:

```go
rpc := rpcclient.NewHTTPClient("<gno_chain_endpoint>")
```

It seems that NewHTTPClient returns 2 values
```go
func NewHTTPClient(rpcURL string) (*RPCClient, error);
``` 
and in the example we assign only one variable.

I updated the examples with:
```go
rpc, err := rpcclient.NewHTTPClient("<gno.land_remote_endpoint>")
if err != nil {
    panic(err)
}
```

There is also a step where `crypto.AddressFromBech32` is used but I
didn't found when the `crypto` was imported so I also added it in the
doc:

```go
import (
    ...
    crypto "github.com/gnolang/gno/tm2/pkg/crypto"
)
```

---------

Co-authored-by: Morgan <[email protected]>
  • Loading branch information
Molaryy and thehowl authored Jun 19, 2024
1 parent 813cb0f commit 028a4ed
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/how-to-guides/connecting-from-go.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ A few things to note:
You can initialize the RPC Client used to connect to the Gno.land network with
the following line:
```go
rpc := rpcclient.NewHTTPClient("<gno_chain_endpoint>")
rpc, err := rpcclient.NewHTTPClient("<gno.land_remote_endpoint>")
if err != nil {
panic(err)
}
```

A list of Gno.land network endpoints & chain IDs can be found in the [Gno RPC
Expand Down Expand Up @@ -139,7 +142,10 @@ func main() {
}

// Initialize the RPC client
rpc := rpcclient.NewHTTPClient("<gno.land_remote_endpoint>")
rpc, err := rpcclient.NewHTTPClient("<gno.land_remote_endpoint>")
if err != nil {
panic(err)
}

// Initialize the gnoclient
client := gnoclient.Client{
Expand All @@ -158,6 +164,13 @@ To send transactions to the chain, we need to know the account number (ID) and
sequence (nonce). We can get this information by querying the chain with the
`QueryAccount` function:

```go
import (
...
"github.com/gnolang/gno/tm2/pkg/crypto"
)
```

```go
// Convert Gno address string to `crypto.Address`
addr, err := crypto.AddressFromBech32("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // your Gno address
Expand Down

0 comments on commit 028a4ed

Please sign in to comment.