UNPKG

micro-stacks

Version:

Tiny libraries for building Stacks apps.

8 lines (5 loc) 2.96 kB
import { TransactionVersion, ChainID, fetchPrivate } from 'micro-stacks/common'; export { ChainID, TransactionVersion } from 'micro-stacks/common'; var g="https://stacks-node-api.mainnet.stacks.co",p="https://stacks-node-api.testnet.stacks.co",d="http://localhost:3999",i=class{version=TransactionVersion.Mainnet;chainId=ChainID.Mainnet;broadcastEndpoint="/v2/transactions";transferFeeEstimateEndpoint="/v2/fees/transfer";accountEndpoint="/v2/accounts";contractAbiEndpoint="/v2/contracts/interface";readOnlyFunctionCallEndpoint="/v2/contracts/call-read";bnsLookupUrl;_coreApiUrl;fetcher;get coreApiUrl(){return this._coreApiUrl}set coreApiUrl(t){throw new Error("Cannot modify property `coreApiUrl` after object initialization")}constructor(t={url:g}){if(!t.url&&!t.coreApiUrl)throw Error("[miro-stacks] Network initialized with no api url");this._coreApiUrl=t.url||t.coreApiUrl,this.bnsLookupUrl=t.bnsLookupUrl||t.url||t.coreApiUrl,this.fetcher=t.fetcher||fetchPrivate;}getCoreApiUrl=()=>this._coreApiUrl;isMainnet=()=>this.version===TransactionVersion.Mainnet;getBroadcastApiUrl=()=>`${this.getCoreApiUrl()}${this.broadcastEndpoint}`;getTransferFeeEstimateApiUrl=()=>`${this.getCoreApiUrl()}${this.transferFeeEstimateEndpoint}`;getAccountApiUrl=t=>`${this.getCoreApiUrl()}${this.accountEndpoint}/${t}?proof=0`;getAbiApiUrl=(t,e)=>`${this.getCoreApiUrl()}${this.contractAbiEndpoint}/${t}/${e}`;getReadOnlyFunctionCallApiUrl=(t,e,r)=>`${this.getCoreApiUrl()}${this.readOnlyFunctionCallEndpoint}/${t}/${e}/${encodeURIComponent(r)}`;getInfoUrl=()=>`${this.getCoreApiUrl()}/v2/info`;getBlockTimeInfoUrl=()=>`${this.getCoreApiUrl()}/extended/v1/info/network_block_times`;getPoxInfoUrl=()=>`${this.getCoreApiUrl()}/v2/pox`;getRewardsUrl=(t,e)=>{let r=`${this.getCoreApiUrl()}/extended/v1/burnchain/rewards/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r};getRewardsTotalUrl=t=>`${this.getCoreApiUrl()}/extended/v1/burnchain/rewards/${t}/total`;getRewardHoldersUrl=(t,e)=>{let r=`${this.getCoreApiUrl()}/extended/v1/burnchain/reward_slot_holders/${t}`;return e&&(r=`${r}?limit=${e.limit}&offset=${e.offset}`),r};getStackerInfoUrl=(t,e)=>`${this.getCoreApiUrl()}${this.readOnlyFunctionCallEndpoint} ${t}/${e}/get-stacker-info`;getNameInfo(t){let e=`${this.bnsLookupUrl}/v1/names/${t}`;return this.fetcher(e).then(r=>{if(r.status===404)throw new Error("Name not found");if(r.status!==200)throw new Error(`Bad response status: ${r.status}`);return r.json()}).then(r=>r.address?Object.assign({},r,{address:r.address}):r)}},l=class extends i{version=TransactionVersion.Testnet;chainId=ChainID.Testnet;constructor(t={url:p,fetcher:fetchPrivate}){super(t);}},c=class extends i{version=TransactionVersion.Testnet;chainId=ChainID.Testnet;constructor(t={url:d,fetcher:fetchPrivate}){super(t);}}; export { g as HIRO_MAINNET_DEFAULT, d as HIRO_MOCKNET_DEFAULT, p as HIRO_TESTNET_DEFAULT, i as StacksMainnet, c as StacksMocknet, l as StacksTestnet };