go-stacks

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2024 License: MIT

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

Class Method HTTP request Description
AccountsAPI GetAccountAssets Get /extended/v1/address/{principal}/assets Get account assets
AccountsAPI GetAccountBalance Get /extended/v1/address/{principal}/balances Get account balances
AccountsAPI GetAccountInbound Get /extended/v1/address/{principal}/stx_inbound Get inbound STX transfers
AccountsAPI GetAccountInfo Get /v2/accounts/{principal} Get account info
AccountsAPI GetAccountNonces Get /extended/v1/address/{principal}/nonces Get the latest nonce used by an account
AccountsAPI GetAccountStxBalance Get /extended/v1/address/{principal}/stx Get account STX balance
AccountsAPI GetAccountTransactions Get /extended/v1/address/{principal}/transactions Get account transactions
AccountsAPI GetAccountTransactionsWithTransfers Get /extended/v1/address/{principal}/transactions_with_transfers Get account transactions including STX transfers for each transaction.
AccountsAPI GetSingleTransactionWithTransfers Get /extended/v1/address/{principal}/{tx_id}/with_transfers Get account transaction information for specific transaction
BlocksAPI GetAverageBlockTimes Get /extended/v2/blocks/average-times Get average block times
BlocksAPI GetBlock Get /extended/v2/blocks/{height_or_hash} Get block
BlocksAPI GetBlockByBurnBlockHash Get /extended/v1/block/by_burn_block_hash/{burn_block_hash} Get block by burnchain block hash
BlocksAPI GetBlockByBurnBlockHeight Get /extended/v1/block/by_burn_block_height/{burn_block_height} Get block by burnchain height
BlocksAPI GetBlockByHash Get /extended/v1/block/{hash} Get block by hash
BlocksAPI GetBlockByHeight Get /extended/v1/block/by_height/{height} Get block by height
BlocksAPI GetBlockList Get /extended/v1/block Get recent blocks
BlocksAPI GetBlocks Get /extended/v2/blocks Get blocks
BlocksAPI GetBlocksByBurnBlock Get /extended/v2/burn-blocks/{height_or_hash}/blocks Get blocks by burn block
BurnBlocksAPI GetBurnBlock Get /extended/v2/burn-blocks/{height_or_hash} Get burn block
BurnBlocksAPI GetBurnBlocks Get /extended/v2/burn-blocks Get burn blocks
FaucetsAPI RunFaucetBtc Post /extended/v1/faucets/btc Add testnet BTC tokens to address
FaucetsAPI RunFaucetStx Post /extended/v1/faucets/stx Get STX testnet tokens
FeesAPI FetchFeeRate Post /extended/v1/fee_rate Fetch fee rate
FeesAPI GetFeeTransfer Get /v2/fees/transfer Get estimated fee
FeesAPI PostFeeTransaction Post /v2/fees/transaction Get approximate fees for a given transaction
InfoAPI GetCoreApiInfo Get /v2/info Get Core API info
InfoAPI GetNetworkBlockTimeByNetwork Get /extended/v1/info/network_block_time/{network} Get a given network's target block time
InfoAPI GetNetworkBlockTimes Get /extended/v1/info/network_block_times Get the network target block time
InfoAPI GetPoxInfo Get /v2/pox Get Proof-of-Transfer details
InfoAPI GetStatus Get /extended API status
InfoAPI GetStxSupply Get /extended/v1/stx_supply Get total and unlocked STX supply
InfoAPI GetStxSupplyCirculatingPlain Get /extended/v1/stx_supply/circulating/plain Get circulating STX supply in plain text format
InfoAPI GetStxSupplyTotalSupplyPlain Get /extended/v1/stx_supply/total/plain Get total STX supply in plain text format
InfoAPI GetTotalStxSupplyLegacyFormat Get /extended/v1/stx_supply/legacy_format Get total and unlocked STX supply (results formatted the same as the legacy 1.0 API)
MempoolAPI GetMempoolFeePriorities Get /extended/v2/mempool/fees Get mempool transaction fee priorities
MicroblocksAPI GetMicroblockByHash Get /extended/v1/microblock/{hash} Get microblock
MicroblocksAPI GetMicroblockList Get /extended/v1/microblock Get recent microblocks
MicroblocksAPI GetUnanchoredTxs Get /extended/v1/microblock/unanchored/txs Get the list of current transactions that belong to unanchored microblocks
NamesAPI FetchSubdomainsListForName Get /v1/names/{name}/subdomains Get Name Subdomains
NamesAPI FetchZoneFile Get /v1/names/{name}/zonefile Get Zone File
NamesAPI GetAllNames Get /v1/names Get All Names
NamesAPI GetAllNamespaces Get /v1/namespaces Get All Namespaces
NamesAPI GetHistoricalZoneFile Get /v1/names/{name}/zonefile/{zoneFileHash} Get Historical Zone File
NamesAPI GetNameInfo Get /v1/names/{name} Get Name Details
NamesAPI GetNamePrice Get /v2/prices/names/{name} Get Name Price
NamesAPI GetNamesOwnedByAddress Get /v1/addresses/{blockchain}/{address} Get Names Owned by Address
NamesAPI GetNamespaceNames Get /v1/namespaces/{tld}/names Get Namespace Names
NamesAPI GetNamespacePrice Get /v2/prices/namespaces/{tld} Get Namespace Price
NonFungibleTokensAPI GetNftHistory Get /extended/v1/tokens/nft/history Non-Fungible Token history
NonFungibleTokensAPI GetNftHoldings Get /extended/v1/tokens/nft/holdings Non-Fungible Token holdings
NonFungibleTokensAPI GetNftMints Get /extended/v1/tokens/nft/mints Non-Fungible Token mints
ProofOfTransferAPI GetPoxCycle Get /extended/v2/pox/cycles/{cycle_number} Get PoX cycle
ProofOfTransferAPI GetPoxCycleSigner Get /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key} Get signer in PoX cycle
ProofOfTransferAPI GetPoxCycleSignerStackers Get /extended/v2/pox/cycles/{cycle_number}/signers/{signer_key}/stackers Get stackers for signer in PoX cycle
ProofOfTransferAPI GetPoxCycleSigners Get /extended/v2/pox/cycles/{cycle_number}/signers Get signers in PoX cycle
ProofOfTransferAPI GetPoxCycles Get /extended/v2/pox/cycles Get PoX cycles
RosettaAPI RosettaAccountBalance Post /rosetta/v1/account/balance Get an Account Balance
RosettaAPI RosettaBlock Post /rosetta/v1/block Get a Block
RosettaAPI RosettaBlockTransaction Post /rosetta/v1/block/transaction Get a Block Transaction
RosettaAPI RosettaConstructionCombine Post /rosetta/v1/construction/combine Create Network Transaction from Signatures
RosettaAPI RosettaConstructionDerive Post /rosetta/v1/construction/derive Derive an AccountIdentifier from a PublicKey
RosettaAPI RosettaConstructionHash Post /rosetta/v1/construction/hash Get the Hash of a Signed Transaction
RosettaAPI RosettaConstructionMetadata Post /rosetta/v1/construction/metadata Get Metadata for Transaction Construction
RosettaAPI RosettaConstructionParse Post /rosetta/v1/construction/parse Parse a Transaction
RosettaAPI RosettaConstructionPayloads Post /rosetta/v1/construction/payloads Generate an Unsigned Transaction and Signing Payloads
RosettaAPI RosettaConstructionPreprocess Post /rosetta/v1/construction/preprocess Create a Request to Fetch Metadata
RosettaAPI RosettaConstructionSubmit Post /rosetta/v1/construction/submit Submit a Signed Transaction
RosettaAPI RosettaMempool Post /rosetta/v1/mempool Get All Mempool Transactions
RosettaAPI RosettaMempoolTransaction Post /rosetta/v1/mempool/transaction Get a Mempool Transaction
RosettaAPI RosettaNetworkList Post /rosetta/v1/network/list Get List of Available Networks
RosettaAPI RosettaNetworkOptions Post /rosetta/v1/network/options Get Network Options
RosettaAPI RosettaNetworkStatus Post /rosetta/v1/network/status Get Network Status
SearchAPI SearchById Get /extended/v1/search/{id} Search
SmartContractsAPI CallReadOnlyFunction Post /v2/contracts/call-read/{contract_address}/{contract_name}/{function_name} Call read-only function
SmartContractsAPI GetContractById Get /extended/v1/contract/{contract_id} Get contract info
SmartContractsAPI GetContractDataMapEntry Post /v2/map_entry/{contract_address}/{contract_name}/{map_name} Get specific data-map inside a contract
SmartContractsAPI GetContractEventsById Get /extended/v1/contract/{contract_id}/events Get contract events
SmartContractsAPI GetContractInterface Get /v2/contracts/interface/{contract_address}/{contract_name} Get contract interface
SmartContractsAPI GetContractSource Get /v2/contracts/source/{contract_address}/{contract_name} Get contract source
SmartContractsAPI GetContractsByTrait Get /extended/v1/contract/by_trait Get contracts by trait
SmartContractsAPI GetSmartContractsStatus Get /extended/v2/smart-contracts/status Get smart contracts status
StackingAPI GetPoolDelegations Get /extended/beta/stacking/{pool_principal}/delegations Stacking pool members
StackingRewardsAPI GetBurnchainRewardList Get /extended/v1/burnchain/rewards Get recent burnchain reward recipients
StackingRewardsAPI GetBurnchainRewardListByAddress Get /extended/v1/burnchain/rewards/{address} Get recent burnchain reward for the given recipient
StackingRewardsAPI GetBurnchainRewardSlotHolders Get /extended/v1/burnchain/reward_slot_holders Get recent reward slot holders
StackingRewardsAPI GetBurnchainRewardSlotHoldersByAddress Get /extended/v1/burnchain/reward_slot_holders/{address} Get recent reward slot holder entries for the given address
StackingRewardsAPI GetBurnchainRewardsTotalByAddress Get /extended/v1/burnchain/rewards/{address}/total Get total burnchain rewards for the given recipient
TransactionsAPI GetAddressMempoolTransactions Get /extended/v1/address/{address}/mempool Transactions for address
TransactionsAPI GetAddressTransactionEvents Get /extended/v2/addresses/{address}/transactions/{tx_id}/events Get events for an address transaction
TransactionsAPI GetAddressTransactions Get /extended/v2/addresses/{address}/transactions Get address transactions
TransactionsAPI GetDroppedMempoolTransactionList Get /extended/v1/tx/mempool/dropped Get dropped mempool transactions
TransactionsAPI GetFilteredEvents Get /extended/v1/tx/events Transaction Events
TransactionsAPI GetMempoolTransactionList Get /extended/v1/tx/mempool Get mempool transactions
TransactionsAPI GetMempoolTransactionStats Get /extended/v1/tx/mempool/stats Get statistics for mempool transactions
TransactionsAPI GetRawTransactionById Get /extended/v1/tx/{tx_id}/raw Get Raw Transaction
TransactionsAPI GetTransactionById Get /extended/v1/tx/{tx_id} Get transaction
TransactionsAPI GetTransactionList Get /extended/v1/tx Get recent transactions
TransactionsAPI GetTransactionsByBlock Get /extended/v2/blocks/{height_or_hash}/transactions Get transactions by block
TransactionsAPI GetTransactionsByBlockHash Get /extended/v1/tx/block/{block_hash} Transactions by block hash
TransactionsAPI GetTransactionsByBlockHeight Get /extended/v1/tx/block_height/{height} Transactions by block height
TransactionsAPI GetTxListDetails Get /extended/v1/tx/multiple Get list of details for transactions
TransactionsAPI PostCoreNodeTransactions Post /v2/transactions Broadcast raw transaction

Documentation For Models

Directories

Path Synopsis
stacks
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL