From f1d56eb9fddece6c255b40c6256b4d0826e8f1a5 Mon Sep 17 00:00:00 2001 From: aggelossik Date: Tue, 5 Dec 2023 23:14:06 +0200 Subject: [PATCH] docs: Update 01-go-client.md improving (#3790) * docs: Update 01-go-client.md comments broadcasting a transaction to create a post and store the response in txResp * docs: Update 01-go-client.md Adding description on running the client app from a remote/diff machine and also a small intro to test keyring * docs: Update 01-go-client.md adding the test keyring backend and define the path * docs:Update 01-go-client.md update documentation changes, changed the dependency to the latest cli stable version, new section creating a client for the blog from a remote location (node and client not on the same system) * docs:Update 01-go-client.md documentation update of the client creation including new section for remote client require from github.com/user/blog and keyring backend example with test * docs: Update 01-go-client.md changed the word node to repository * Update docs/versioned_docs/version-v0.27.2/03-clients/01-go-client.md Co-authored-by: Danny * Apply suggestions from code review Co-authored-by: Danny --------- Co-authored-by: Danilo Pantani Co-authored-by: Danny Co-authored-by: Danny --- .../03-clients/01-go-client.md | 69 ++++++++++++++++++- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/docs/versioned_docs/version-v0.27.2/03-clients/01-go-client.md b/docs/versioned_docs/version-v0.27.2/03-clients/01-go-client.md index 1c6ca746b8..36bdc90838 100644 --- a/docs/versioned_docs/version-v0.27.2/03-clients/01-go-client.md +++ b/docs/versioned_docs/version-v0.27.2/03-clients/01-go-client.md @@ -77,11 +77,11 @@ To import dependencies for your package, you can add the following code to the ```text title="blogclient/go.mod" module blogclient -go 1.19 +go 1.20 require ( blog v0.0.0-00010101000000-000000000000 - github.com/ignite/cli v0.25.2 + github.com/ignite/cli v0.27.2 ) replace blog => ../blog @@ -94,7 +94,7 @@ Your package will import two dependencies: * `ignite` for the `cosmosclient` package The `replace` directive uses the package from the local `blog` directory and is -specified as a relative path to the `blogclient` directory. +specified as a relative path to the `blogclient` directory. Cosmos SDK uses a custom version of the `protobuf` package, so use the `replace` directive to specify the correct dependency. @@ -211,6 +211,69 @@ package documentation for This documentation provides information on how to use the `Client` type with `Options` and `KeyringBackend`. +## Blockchain and Client App Are on Different Machines + +If the blockchain and the client app are not on the same machine, replace ../blog with the github +repository pointing to your blog GitHub repository: + +dependencies for your package + +`go.mod` file: + +```text title="blogclient/go.mod" +... +replace blog => github.com//blog v0.0.0-00010101000000-000000000000 +... +``` + +and `main.go` file: + +```go title="blogclient/main.go" + // Importing the types package of your blog blockchain + "github.com//blog/x/blog/types" +``` + +Then, update the dependencies again: + +```bash +go mod tidy +``` + +## Using the Test Keyring Backend + +***Only for testing*** + +Create a new directory inside the blog client named 'keyring-test'. Next, export the blockchain account keys from the user you want to be sign and broadcast the transaction too. After exporting, import the keys +to the 'keyring-test' directory you just created in root directory of your client app. You can use the following `ignite account import` command: + +```bash +ignite account import alice --keyring-dir /path/to/client/blogclient/keyring-test +``` + +Define the path inside 'main.go': + +```go title="blogclient/main.go" +. +. +. +func main() { + ctx := context.Background() + addressPrefix := "cosmos" + + // Create a Cosmos client instance + client, err := cosmosclient.New(ctx, cosmosclient.WithAddressPrefix(addressPrefix), + cosmosclient.WithKeyringBackend("test"), cosmosclient.WithKeyringDir(".") ) + if err != nil { + log.Fatal(err) + } + + // Account `alice` was initialized during `ignite chain serve` + accountName :="aliceAddress" +. +. +. +``` + ## Run the blockchain and the client Make sure your blog blockchain is still running with `ignite chain serve`.