How to Create a Ubiquity Client Within Your Scripts

Language Code Snippet Readme File
JAVA UbiquityClient client = new UbiquityClientBuilder().authBearerToken(“token“).build();

Block block = client.block().getBlock(Platforms.BITCOIN, Networks.MAIN_NET, “current“);

JAVA README
Python import ubiquity
from ubiquity.api import blocks_apiconf = ubiquity.Configuration(
    access_token=”<token>
)with ubiquity.ApiClient(conf) as client:
    blocks_api_instance = blocks_api.BlocksApi(client)
    platform = “ethereum
    network = “mainnetblock = blocks_api_instance.get_block(platform, network, “current“)
Python README
Go package main

import (

“context”

“fmt”

ubiquity “gitlab.com/Blockdaemon/ubiquity/ubiquity-go-client/pkg/client”

“strings”

)

func main() {

apiClient := ubiquity.NewAPIClient(ubiquity.NewConfiguration())

pl := “bitcoin”

accessToken := “put your token here”

ctx := context.WithValue(context.Background(), ubiquity.ContextAccessToken, accessToken)

block, resp, err := apiClient.BlocksAPI.GetBlock(ctx, pl, “mainnet”, “current”).Execute()

if err != nil {

panic(fmt.Errorf(“failed to get a current %s block: got status ‘%s’ and error ‘%v'”,

strings.Title(pl), resp.Status, err))

}

fmt.Printf(“Current %s block comes with ID ‘%s’ and transactions count %d\n”,

strings.Title(pl), block.GetId(), len(block.GetTxs()))

}

Go README