Categorygithub.com/cbadawi/go-stacks
repository
0.1.0
Repository: https://github.com/cbadawi/go-stacks.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

go-stacks

Introduction

go-stacks is a golang sdk for interacting with the stacks blockchain. This SDK was generated using the Hiro's OpenAPI specification and modified where needed.

Requirements

The SDK requires Go version 1.22 or above.

Building

Install Dependencies

Resolve all the SDK dependencies, using the go get command.

TODOs

  • fix and improve testing
  • implement (de)serializing transactions

Quick Start

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/cbadawi/go-stacks/stacks/api"
	"github.com/cbadawi/go-stacks/stacks/config"
)

func main() {
	principal := "SM3KNVZS30WM7F89SXKVVFY4SN9RMPZZ9FX929N0V" // string | Stacks address or a Contract identifier
	unanchored := false                                      // bool | Include transaction data from unanchored (i.e. unconfirmed) microblocks (optional) (default to false)
	untilBlock := "400000"                                   //"60000"                                   // string | returned data representing the state up until that point in time, rather than the current block. (optional)

	configuration := config.NewConfiguration()
	configuration.Logger.Verbose = true // defaults to false
	// configuration.Host = "http://localhost:3999" // can define a custom host
	apiClient := api.NewAPIClient(configuration)
	resp, r, err := apiClient.AccountsAPI.GetAccountBalance(context.Background(), principal).Unanchored(unanchored).UntilBlock(untilBlock).Execute()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error when calling `AccountsAPI.GetAccountBalance``: %v\n", err)
		fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
	}
	// response from `GetAccountBalance`: AddressBalanceResponse
	fmt.Fprintf(os.Stdout, "Response from `AccountsAPI.GetAccountBalance`: %v\n", resp.Stx.Balance)
}

Documentation for API Endpoints

ClassMethodHTTP requestDescription
AccountsAPIGetAccountAssetsGet /extended/v1/address/{principal}/assetsGet account assets
AccountsAPIGetAccountBalanceGet /extended/v1/address/{principal}/balancesGet account balances
AccountsAPIGetAccountInboundGet /extended/v1/address/{principal}/stx_inboundGet inbound STX transfers
AccountsAPIGetAccountInfoGet /v2/accounts/{principal}Get account info
AccountsAPIGetAccountNoncesGet /extended/v1/address/{principal}/noncesGet the latest nonce used by an account
AccountsAPIGetAccountStxBalanceGet /extended/v1/address/{principal}/stxGet account STX balance
AccountsAPIGetAccountTransactionsGet /extended/v1/address/{principal}/transactionsGet account transactions
AccountsAPIGetAccountTransactionsWithTransfersGet /extended/v1/address/{principal}/transactions_with_transfersGet account transactions including STX transfers for each transaction.
AccountsAPIGetSingleTransactionWithTransfersGet /extended/v1/address/{principal}/{tx_id}/with_transfersGet account transaction information for specific transaction
BlocksAPIGetAverageBlockTimesGet /extended/v2/blocks/average-timesGet average block times
BlocksAPIGetBlockGet /extended/v2/blocks/{height_or_hash}Get block
BlocksAPIGetBlockByBurnBlockHashGet /extended/v1/block/by_burn_block_hash/{burn_block_hash}Get block by burnchain block hash
BlocksAPIGetBlockByBurnBlockHeightGet /extended/v1/block/by_burn_block_height/{burn_block_height}Get block by burnchain height
BlocksAPIGetBlockByHashGet /extended/v1/block/{hash}Get block by hash
BlocksAPIGetBlockByHeightGet /extended/v1/block/by_height/{height}Get block by height
BlocksAPIGetBlockListGet /extended/v1/blockGet recent blocks
BlocksAPIGetBlocksGet /extended/v2/blocksGet blocks
BlocksAPIGetBlocksByBurnBlockGet /extended/v2/burn-blocks/{height_or_hash}/blocksGet blocks by burn block
BurnBlocksAPIGetBurnBlockGet /extended/v2/burn-blocks/{height_or_hash}Get burn block
BurnBlocksAPIGetBurnBlocksGet /extended/v2/burn-blocksGet burn blocks
FaucetsAPIRunFaucetBtcPost /extended/v1/faucets/btcAdd testnet BTC tokens to address
FaucetsAPIRunFaucetStxPost /extended/v1/faucets/stxGet STX testnet tokens
FeesAPIFetchFeeRatePost /extended/v1/fee_rateFetch fee rate
FeesAPIGetFeeTransferGet /v2/fees/transferGet estimated fee
FeesAPIPostFeeTransactionPost /v2/fees/transactionGet approximate fees for a given transaction
InfoAPIGetCoreApiInfoGet /v2/infoGet Core API info
InfoAPIGetNetworkBlockTimeByNetworkGet /extended/v1/info/network_block_time/{network}Get a given network's target block time
InfoAPIGetNetworkBlockTimesGet /extended/v1/info/network_block_timesGet the network target block time
InfoAPIGetPoxInfoGet /v2/poxGet Proof-of-Transfer details
InfoAPIGetStatusGet /extendedAPI status
InfoAPIGetStxSupplyGet /extended/v1/stx_supplyGet total and unlocked STX supply
InfoAPIGetStxSupplyCirculatingPlainGet /extended/v1/stx_supply/circulating/plainGet circulating STX supply in plain text format
InfoAPIGetStxSupplyTotalSupplyPlainGet /extended/v1/stx_supply/total/plainGet total STX supply in plain text format
InfoAPIGetTotalStxSupplyLegacyFormatGet /extended/v1/stx_supply/legacy_formatGet total and unlocked STX supply (results formatted the same as the legacy 1.0 API)
MempoolAPIGetMempoolFeePrioritiesGet /extended/v2/mempool/feesGet mempool transaction fee priorities
MicroblocksAPIGetMicroblockByHashGet /extended/v1/microblock/{hash}Get microblock
MicroblocksAPIGetMicroblockListGet /extended/v1/microblockGet recent microblocks
MicroblocksAPIGetUnanchoredTxsGet /extended/v1/microblock/unanchored/txsGet the list of current transactions that belong to unanchored microblocks
NamesAPIFetchSubdomainsListForNameGet /v1/names/{name}/subdomainsGet Name Subdomains
NamesAPIFetchZoneFileGet /v1/names/{name}/zonefileGet Zone File
NamesAPIGetAllNamesGet /v1/namesGet All Names
NamesAPIGetAllNamespacesGet /v1/namespacesGet All Namespaces
NamesAPIGetHistoricalZoneFileGet /v1/names/{name}/zonefile/{zoneFileHash}Get Historical Zone File
NamesAPIGetNameInfoGet /v1/names/{name}Get Name Details
NamesAPIGetNamePriceGet /v2/prices/names/{name}Get Name Price
NamesAPIGetNamesOwnedByAddressGet /v1/addresses/{blockchain}/{address}Get Names Owned by Address
NamesAPIGetNamespaceNamesGet /v1/namespaces/{tld}/namesGet Namespace Names
NamesAPIGetNamespacePriceGet /v2/prices/namespaces/{tld}Get Namespace Price
NonFungibleTokensAPIGetNftHistoryGet /extended/v1/tokens/nft/historyNon-Fungible Token history
NonFungibleTokensAPIGetNftHoldingsGet /extended/v1/tokens/nft/holdingsNon-Fungible Token holdings
NonFungibleTokensAPIGetNftMintsGet /extended/v1/tokens/nft/mintsNon-Fungible Token mints
ProofOfTransferAPIGetPoxCycleGet /extended/v2/pox/cycles/{cycle_number}Get PoX cycle
ProofOfTransferAPIGetPoxCycleSignerGet /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}Get signer in PoX cycle
ProofOfTransferAPIGetPoxCycleSignerStackersGet /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackersGet stackers for signer in PoX cycle
ProofOfTransferAPIGetPoxCycleSignersGet /extended/v2/pox/cycles/{cycle_number}/signersGet signers in PoX cycle
ProofOfTransferAPIGetPoxCyclesGet /extended/v2/pox/cyclesGet PoX cycles
RosettaAPIRosettaAccountBalancePost /rosetta/v1/account/balanceGet an Account Balance
RosettaAPIRosettaBlockPost /rosetta/v1/blockGet a Block
RosettaAPIRosettaBlockTransactionPost /rosetta/v1/block/transactionGet a Block Transaction
RosettaAPIRosettaConstructionCombinePost /rosetta/v1/construction/combineCreate Network Transaction from Signatures
RosettaAPIRosettaConstructionDerivePost /rosetta/v1/construction/deriveDerive an AccountIdentifier from a PublicKey
RosettaAPIRosettaConstructionHashPost /rosetta/v1/construction/hashGet the Hash of a Signed Transaction
RosettaAPIRosettaConstructionMetadataPost /rosetta/v1/construction/metadataGet Metadata for Transaction Construction
RosettaAPIRosettaConstructionParsePost /rosetta/v1/construction/parseParse a Transaction
RosettaAPIRosettaConstructionPayloadsPost /rosetta/v1/construction/payloadsGenerate an Unsigned Transaction and Signing Payloads
RosettaAPIRosettaConstructionPreprocessPost /rosetta/v1/construction/preprocessCreate a Request to Fetch Metadata
RosettaAPIRosettaConstructionSubmitPost /rosetta/v1/construction/submitSubmit a Signed Transaction
RosettaAPIRosettaMempoolPost /rosetta/v1/mempoolGet All Mempool Transactions
RosettaAPIRosettaMempoolTransactionPost /rosetta/v1/mempool/transactionGet a Mempool Transaction
RosettaAPIRosettaNetworkListPost /rosetta/v1/network/listGet List of Available Networks
RosettaAPIRosettaNetworkOptionsPost /rosetta/v1/network/optionsGet Network Options
RosettaAPIRosettaNetworkStatusPost /rosetta/v1/network/statusGet Network Status
SearchAPISearchByIdGet /extended/v1/search/{id}Search
SmartContractsAPICallReadOnlyFunctionPost /v2/contracts/call-read/{contract_address}/{contract_name}/{function_name}Call read-only function
SmartContractsAPIGetContractByIdGet /extended/v1/contract/{contract_id}Get contract info
SmartContractsAPIGetContractDataMapEntryPost /v2/map_entry/{contract_address}/{contract_name}/{map_name}Get specific data-map inside a contract
SmartContractsAPIGetContractEventsByIdGet /extended/v1/contract/{contract_id}/eventsGet contract events
SmartContractsAPIGetContractInterfaceGet /v2/contracts/interface/{contract_address}/{contract_name}Get contract interface
SmartContractsAPIGetContractSourceGet /v2/contracts/source/{contract_address}/{contract_name}Get contract source
SmartContractsAPIGetContractsByTraitGet /extended/v1/contract/by_traitGet contracts by trait
SmartContractsAPIGetSmartContractsStatusGet /extended/v2/smart-contracts/statusGet smart contracts status
StackingAPIGetPoolDelegationsGet /extended/beta/stacking/{pool_principal}/delegationsStacking pool members
StackingRewardsAPIGetBurnchainRewardListGet /extended/v1/burnchain/rewardsGet recent burnchain reward recipients
StackingRewardsAPIGetBurnchainRewardListByAddressGet /extended/v1/burnchain/rewards/{address}Get recent burnchain reward for the given recipient
StackingRewardsAPIGetBurnchainRewardSlotHoldersGet /extended/v1/burnchain/reward_slot_holdersGet recent reward slot holders
StackingRewardsAPIGetBurnchainRewardSlotHoldersByAddressGet /extended/v1/burnchain/reward_slot_holders/{address}Get recent reward slot holder entries for the given address
StackingRewardsAPIGetBurnchainRewardsTotalByAddressGet /extended/v1/burnchain/rewards/{address}/totalGet total burnchain rewards for the given recipient
TransactionsAPIGetAddressMempoolTransactionsGet /extended/v1/address/{address}/mempoolTransactions for address
TransactionsAPIGetAddressTransactionEventsGet /extended/v2/addresses/{address}/transactions/{tx_id}/eventsGet events for an address transaction
TransactionsAPIGetAddressTransactionsGet /extended/v2/addresses/{address}/transactionsGet address transactions
TransactionsAPIGetDroppedMempoolTransactionListGet /extended/v1/tx/mempool/droppedGet dropped mempool transactions
TransactionsAPIGetFilteredEventsGet /extended/v1/tx/eventsTransaction Events
TransactionsAPIGetMempoolTransactionListGet /extended/v1/tx/mempoolGet mempool transactions
TransactionsAPIGetMempoolTransactionStatsGet /extended/v1/tx/mempool/statsGet statistics for mempool transactions
TransactionsAPIGetRawTransactionByIdGet /extended/v1/tx/{tx_id}/rawGet Raw Transaction
TransactionsAPIGetTransactionByIdGet /extended/v1/tx/{tx_id}Get transaction
TransactionsAPIGetTransactionListGet /extended/v1/txGet recent transactions
TransactionsAPIGetTransactionsByBlockGet /extended/v2/blocks/{height_or_hash}/transactionsGet transactions by block
TransactionsAPIGetTransactionsByBlockHashGet /extended/v1/tx/block/{block_hash}Transactions by block hash
TransactionsAPIGetTransactionsByBlockHeightGet /extended/v1/tx/block_height/{height}Transactions by block height
TransactionsAPIGetTxListDetailsGet /extended/v1/tx/multipleGet list of details for transactions
TransactionsAPIPostCoreNodeTransactionsPost /v2/transactionsBroadcast raw transaction

Documentation For Models