Ubiquity-Go-Client
Ubiquity provides a RESTful and uniform way to access blockchain resources, with a rich and reusable model across
multiple cryptocurrencies. See Ubiquity docs
This repo provides a code-generated Go SDK to work with the Ubiquity REST API.
Protocols
Mainnet
The following protocols are currently supported:
- algorand
- bitcoin
- bitcoincash
- dogecoin
- ethereum
- litecoin
- near
- oasis
- polkadot
- solana
- stellar
- tezos
- xrp
Testnet
- bitcoin/testnet
- bitcoincash/testnet
- dogecoin/testnet
- ethereum/goerli
- litecoin/testnet
Note: please use examples/protocols-overview
for most up-to-date list.
Certain resources contain a lot of data, more than what's practical to return for a single request. With the help of
pagination, the data is split across multiple responses. Each response returns a subset of the items requested and a
continuation token.
To get the next batch of items, copy the returned continuation token to the continuation query parameter and repeat the
request with the new URL. In case no continuation token is returned, there is no more data available.
Table of contents
Overview
This API client was generated by the OpenAPI Generator project. By using
the OpenAPI-spec from a remote server, you can easily generate an API client.
- API version: 3.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.GoClientCodegen For more information, please
visit https://blockdaemon.com
Installation
go get gitlab.com/Blockdaemon/ubiquity/ubiquity-go-client
Note: You may need to add this into your ~/.gitconfig
in order to make it work with GitLab sub-modules:
[url "ssh://git@gitlab.com/"]
insteadOf = https://gitlab.com/
To use a proxy, set the environment variable HTTP_PROXY
:
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
Examples
See full examples in the examples
directory:
protocols-overview
- overview of all supported protocols
tx-querying
- querying transaction by id
utxo
- get a list of transaction inputs and outputs by account address
current-block
- getting current block and printing 10 transactions
tx-pagination
- paginating over transactions
tx-send
- sending BTC or ETH transactions and waiting for confirmation throughout Websocket
Configuration of Server URL
Default configuration comes with Servers
field that contains server objects as defined in the OpenAPI specification.
Changing the default Server Configuration
For using other server than the default server defined on index 0 (Prod = https://svc.blockdaemon.com/universal/v1
) set context value ubiquity.ContextServerIndex
of type int
or see the examples.
ctx := context.WithValue(context.Background(), ubiquity.ContextServerIndex, 1)
URLs Configuration per Operation
Each operation can use different server URL defined using OperationServers
map in the Configuration
. An operation is uniquely identified by "{classname}Service.{nickname}"
string. Similar rules for overriding default operation server index and variables applies by using ubiquity.ContextOperationServerIndices
and ubiquity.ContextOperationServerVariables
context maps.
ctx := context.WithValue(context.Background(), ubiquity.ContextOperationServerIndices, map[string]int{
"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), ubiquity.ContextOperationServerVariables, map[string]map[string]string{
"{classname}Service.{nickname}": {
"port": "8443",
},
})
Authorization
bearerAuth
- Type: HTTP Bearer token authentication
Example
ctxWithAuth := context.WithValue(context.Background(), ubiquity.ContextAccessToken, "BEARERTOKENSTRING")
r, err := client.Service.Operation(ctxWithAuth, args)
Transactions signing
SDK provides a service primitive ubiquitytx.UbiquityTransactionService
that you can use to create, sign and send
transactions of currently supported protocols - BTC and ETH. See code sample tx-send
in examples
folder.
Important Note: for BTC, any amount left after sending to destination and change addresses is automatically paid as
fee.
Websocket support
SDK comes with a support
for Ubiquity Websocket API. Please see the
examples ws-blocks
and tx-send
.
Utility Methods
Due to the fact that model structure members are all pointers, this package contains a number of utility functions to
easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and
returns a pointer to it:
PtrBool
PtrInt
PtrInt32
PtrInt64
PtrFloat
PtrFloat32
PtrFloat64
PtrString
PtrTime
Development
Mocks are generated using https://github.com/vektra/mockery.
Run make build-mocks
from the repository's root directory to re-generate tx
package mocks:
Documentation
Additional documentation and examples can be found in the docs
directory.
Additional Release Notes
(06/01/2022) :Websockets response for subscribers has changed to also add the Revert boolean. This is an additional field and will not
break any existing implementations.