-
Notifications
You must be signed in to change notification settings - Fork 9
Examples: Get Mosaic info
Eleazar Garrido edited this page Jan 13, 2019
·
19 revisions
- Param mosaic - Mosaic identifier.
- Example Mosaic identifier: "nem:xem"
package main
import (
"encoding/json"
"fmt"
"github.com/proximax-storage/nem2-sdk-go/sdk"
"golang.org/x/net/context"
)
// Catapult-api-rest server.
const (
baseUrl = "http://localhost:3000"
networkType = sdk.MijinTest
)
// Simple Mosaic API request
func main() {
conf, err := sdk.NewConfig(baseUrl,networkType)
if err != nil {
panic(err)
}
// Use the default http client
client := sdk.NewClient(nil, conf)
// Create a Mosaic identifier.
// Example Mosaic identifier: "nem:xem"
mosaicId, _ := sdk.NewMosaicIdFromFullName("nem:xem")
// Get mosaic information.
getMosaic, err := client.Mosaic.GetMosaic(context.Background(), mosaicId)
if err != nil {
fmt.Printf("Mosaic.GetMosaic returned error: %s", err)
return
}
getMosaicJson, _ := json.MarshalIndent(getMosaic, "", " ")
fmt.Printf("%s\n\n", string(getMosaicJson))
}
- Param mosaics - A MosaicIds struct.
// Create the Mosaics identifier.
xpxMosaicId, _ := sdk.NewMosaicIdFromFullName("proximax:xpx")
xemMosaicId, _ := sdk.NewMosaicIdFromFullName("nem:xem")
var mosaics []*sdk.MosaicId
// Append attachment into Mosaics
mosaics = append(mosaics, xpxMosaicId)
// Append attachment into Mosaics
mosaics = append(mosaics, xemMosaicId)
getMosaics, err := client.Mosaic.GetMosaics(context.Background(), mosaics)
if err != nil {
fmt.Printf("Mosaic.GetMosaics returned error: %s", err)
return
}
getMosaicsJson, _ := json.MarshalIndent(getMosaics, "", " ")
fmt.Printf("%s\n\n", string(getMosaicsJson))
- Param mosaics - A MosaicIds struct.
// Create the Mosaics identifier.
xpxMosaicId, _ := sdk.NewMosaicIdFromFullName("proximax:xpx")
xemMosaicId, _ := sdk.NewMosaicIdFromFullName("nem:xem")
var mosaics []*sdk.MosaicId
// Append attachment into Mosaics
mosaics = append(mosaics, xpxMosaicId)
// Append attachment into Mosaics
mosaics = append(mosaics, xemMosaicId)
getMosaicNames, err := client.Mosaic.GetMosaicNames(context.Background(), mosaics)
if err != nil {
fmt.Printf("Mosaic.GetMosaicNames returned error: %s", err)
return
}
getMosaicNamesJson, _ := json.MarshalIndent(getMosaicNames, "", " ")
fmt.Printf("%s\n\n", string(getMosaicNamesJson))
- First parameter - A Namespace identifier.
- Second parameter - A Identifier of the mosaic after which we want the transactions to be returned. if left empty, all the masaic related to the Namespace identifier will be returned.
- Param 0 - The number of mosaics to return.
namespaceId, _ := sdk.NewNamespaceIdFromName("nem")
getMosaicsFromNamespace, err := client.Mosaic.GetMosaicsFromNamespace(context.Background(), namespaceId, 0)
if err != nil {
fmt.Printf("Mosaic.GetMosaicsFromNamespace returned error: %s", err)
return
}
for _, m := range getMosaicsFromNamespace {
getMosaicsFromNamespaceJson, _ := json.MarshalIndent(m, "", " ")
fmt.Printf("%s\n\n", string(getMosaicsFromNamespaceJson))
}