Skip to content

Examples: Get Accounts info

Eleazar Garrido edited this page Oct 2, 2018 · 26 revisions

Get AccountInfo for an account.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/proximax-storage/nem2-sdk-go/sdk"
	"golang.org/x/net/context"
)

// Simple Account API request
func main() {

        networkType := sdk.MijinTest

	alicePrivateKey := "814DA2775296E71D461CACA6CB8BF3D0485C522AAAD99C1681A9AE12C402188E"

	aliceAddress, _ := sdk.NewAddressFromPublicKey(alicePrivateKey, networkType)

	conf, err := sdk.LoadTestnetConfig("http://catapult.internal.proximax.io:3000")
	if err != nil {
		panic(err)
	}

	// Use the default http client
	client := sdk.NewClient(nil, conf)

	// Get AccountInfo for an account.
	// Param address - A Address struct.
	accountInfo, resp, err := client.Account.GetAccountInfo(context.Background(), aliceAddress)
	if err != nil {
		fmt.Printf("Account.GetAccountInfo returned error: %s", err)
		return
	}
	accountInfoJson, _ := json.Marshal(accountInfo)
	fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
	fmt.Printf("%s\n\n", string(accountInfoJson))
}

Get AccountsInfo for different accounts.

package main

import (
	"encoding/json"
	"fmt"
	"github.com/proximax-storage/nem2-sdk-go/sdk"
	"golang.org/x/net/context"
)

// Simple Account API request
func main() {

	networkType := sdk.MijinTest

	alicePrivateKey := "814DA2775296E71D461CACA6CB8BF3D0485C522AAAD99C1681A9AE12C402188E"

	carolPrivateKey := "04dd376196603c44a19fd500492e5de12de9ed353de070a788cb21f210645613"

	conf, err := sdk.LoadTestnetConfig("http://catapult.internal.proximax.io:3000")
	if err != nil {
		panic(err)
	}

	// Use the default http client
	client := sdk.NewClient(nil, conf)

	aliceAddress, _ := sdk.NewAddressFromPublicKey(alicePrivateKey, networkType)

	carolAddress, _ := sdk.NewAddressFromPublicKey(carolPrivateKey, networkType)

	var adds []*sdk.Address

	// Append attachment into Address
	adds = append(adds, aliceAddress)
	// Append attachment into Address
	adds = append(adds, carolAddress)

	// Get AccountsInfo for different accounts.
	// Param adds - slice of Address.
	accountsInfo, resp, err := client.Account.GetAccountsInfo(context.Background(), adds)
	if err != nil {
		fmt.Printf("Account.GetAccountsInfo returned error: %s", err)
		return
	}
	accountsInfoJson, _ := json.Marshal(accountsInfo)
	fmt.Printf("Response Status Code == %d\n", resp.StatusCode)
	fmt.Printf("%s\n\n", string(accountsInfoJson))
}