Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stacks/transactions

Package Overview
Dependencies
Maintainers
5
Versions
662
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stacks/transactions - npm Package Compare versions

Comparing version 6.16.2-pr.0746d956.2 to 6.16.2-pr.0c509c33.3

1

dist/builders.d.ts

@@ -10,2 +10,3 @@ import { IntegerType } from '@stacks/common';

export declare function getNonce(address: string, network?: StacksNetworkName | StacksNetwork): Promise<bigint>;
export declare function getNetworkChainID(network: StacksNetwork, useDefaultOnError?: boolean): Promise<number>;
export declare function estimateTransfer(transaction: StacksTransaction, network?: StacksNetworkName | StacksNetwork): Promise<bigint>;

@@ -12,0 +13,0 @@ interface FeeEstimation {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.estimateTransactionFeeWithFallback = exports.estimateTransactionByteLength = exports.sponsorTransaction = exports.getContractMapEntry = exports.callReadOnlyFunction = exports.makeContractNonFungiblePostCondition = exports.makeStandardNonFungiblePostCondition = exports.makeContractFungiblePostCondition = exports.makeStandardFungiblePostCondition = exports.makeContractSTXPostCondition = exports.makeStandardSTXPostCondition = exports.makeContractCall = exports.makeUnsignedContractCall = exports.estimateContractFunctionCall = exports.makeUnsignedContractDeploy = exports.makeContractDeploy = exports.estimateContractDeploy = exports.makeSTXTokenTransfer = exports.makeUnsignedSTXTokenTransfer = exports.getAbi = exports.broadcastRawTransaction = exports.broadcastTransaction = exports.estimateTransaction = exports.estimateTransferUnsafe = exports.estimateTransfer = exports.getNonce = void 0;
exports.estimateTransactionFeeWithFallback = exports.estimateTransactionByteLength = exports.sponsorTransaction = exports.getContractMapEntry = exports.callReadOnlyFunction = exports.makeContractNonFungiblePostCondition = exports.makeStandardNonFungiblePostCondition = exports.makeContractFungiblePostCondition = exports.makeStandardFungiblePostCondition = exports.makeContractSTXPostCondition = exports.makeStandardSTXPostCondition = exports.makeContractCall = exports.makeUnsignedContractCall = exports.estimateContractFunctionCall = exports.makeUnsignedContractDeploy = exports.makeContractDeploy = exports.estimateContractDeploy = exports.makeSTXTokenTransfer = exports.makeUnsignedSTXTokenTransfer = exports.getAbi = exports.broadcastRawTransaction = exports.broadcastTransaction = exports.estimateTransaction = exports.estimateTransferUnsafe = exports.estimateTransfer = exports.getNetworkChainID = exports.getNonce = void 0;
const common_1 = require("@stacks/common");

@@ -47,2 +47,26 @@ const network_1 = require("@stacks/network");

exports.getNonce = getNonce;
async function getNetworkChainID(network, useDefaultOnError = true) {
const url = network.getInfoUrl();
try {
const response = await network.fetchFn(url);
if (!response.ok) {
const msg = await response.text().catch(() => '');
throw new Error(`Bad response status ${response.status} ${response.statusText}: "${msg}"`);
}
const responseJson = await response.json();
return responseJson.network_id;
}
catch (error) {
if (!useDefaultOnError) {
throw error;
}
console.warn(`Error fetching network chain ID from ${url}`, error);
return network.chainId;
}
}
exports.getNetworkChainID = getNetworkChainID;
function isNetworkCustomTestnet(network) {
return (network.version !== constants_1.TransactionVersion.Mainnet &&
new URL(network.coreApiUrl).host !== new URL(network_1.HIRO_TESTNET_DEFAULT).host);
}
async function estimateTransfer(transaction, network) {

@@ -211,2 +235,5 @@ if (transaction.payload.payloadType !== constants_1.PayloadType.TokenTransfer) {

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -328,2 +355,5 @@ }

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -422,2 +452,5 @@ }

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -424,0 +457,0 @@ }

@@ -10,2 +10,3 @@ import { IntegerType } from '@stacks/common';

export declare function getNonce(address: string, network?: StacksNetworkName | StacksNetwork): Promise<bigint>;
export declare function getNetworkChainID(network: StacksNetwork, useDefaultOnError?: boolean): Promise<number>;
export declare function estimateTransfer(transaction: StacksTransaction, network?: StacksNetworkName | StacksNetwork): Promise<bigint>;

@@ -12,0 +13,0 @@ interface FeeEstimation {

import { bytesToHex, hexToBytes, intToBigInt } from '@stacks/common';
import { StacksNetwork, StacksMainnet, StacksTestnet, createFetchFn, } from '@stacks/network';
import { StacksNetwork, StacksMainnet, StacksTestnet, createFetchFn, HIRO_TESTNET_DEFAULT, } from '@stacks/network';
import { c32address } from 'c32check';

@@ -43,2 +43,25 @@ import { createMultiSigSpendingCondition, createSingleSigSpendingCondition, createSponsoredAuth, createStandardAuth, isSingleSig, } from './authorization';

}
export async function getNetworkChainID(network, useDefaultOnError = true) {
const url = network.getInfoUrl();
try {
const response = await network.fetchFn(url);
if (!response.ok) {
const msg = await response.text().catch(() => '');
throw new Error(`Bad response status ${response.status} ${response.statusText}: "${msg}"`);
}
const responseJson = await response.json();
return responseJson.network_id;
}
catch (error) {
if (!useDefaultOnError) {
throw error;
}
console.warn(`Error fetching network chain ID from ${url}`, error);
return network.chainId;
}
}
function isNetworkCustomTestnet(network) {
return (network.version !== TransactionVersion.Mainnet &&
new URL(network.coreApiUrl).host !== new URL(HIRO_TESTNET_DEFAULT).host);
}
export async function estimateTransfer(transaction, network) {

@@ -201,2 +224,5 @@ if (transaction.payload.payloadType !== PayloadType.TokenTransfer) {

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -314,2 +340,5 @@ }

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -406,2 +435,5 @@ }

}
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -408,0 +440,0 @@ }

10

package.json
{
"name": "@stacks/transactions",
"version": "6.16.2-pr.0746d956.2+0746d956",
"version": "6.16.2-pr.0c509c33.3+0c509c33",
"description": "Javascript library for constructing transactions on the Stacks blockchain.",

@@ -30,4 +30,4 @@ "license": "MIT",

"@noble/secp256k1": "1.7.1",
"@stacks/common": "^6.16.2-pr.0746d956.2+0746d956",
"@stacks/network": "^6.16.2-pr.0746d956.2+0746d956",
"@stacks/common": "^6.16.2-pr.0c509c33.3+0c509c33",
"@stacks/network": "^6.16.2-pr.0c509c33.3+0c509c33",
"c32check": "^2.0.0",

@@ -37,3 +37,3 @@ "lodash.clonedeep": "^4.5.0"

"devDependencies": {
"@stacks/encryption": "^6.16.2-pr.0746d956.2+0746d956",
"@stacks/encryption": "^6.16.2-pr.0c509c33.3+0c509c33",
"@types/common-tags": "^1.8.0",

@@ -67,3 +67,3 @@ "@types/elliptic": "^6.4.12",

},
"gitHead": "0746d9569b04bbf33fd4f4deb6f319c38164f390"
"gitHead": "0c509c33441c221b2928d753bf2e9efa6d1bca51"
}

@@ -9,2 +9,3 @@ import { bytesToHex, hexToBytes, IntegerType, intToBigInt } from '@stacks/common';

createFetchFn,
HIRO_TESTNET_DEFAULT,
} from '@stacks/network';

@@ -121,2 +122,33 @@ import { c32address } from 'c32check';

/**
* Fetch the network chain ID from a given network. Typically used for looking up the chain ID for a non-default testnet network.
* @param useDefaultOnError - If the network fetch fails then return the default chain ID already specifed in the `network` arg.
*/
export async function getNetworkChainID(network: StacksNetwork, useDefaultOnError = true) {
const url = network.getInfoUrl();
try {
const response = await network.fetchFn(url);
if (!response.ok) {
const msg = await response.text().catch(() => '');
throw new Error(`Bad response status ${response.status} ${response.statusText}: "${msg}"`);
}
const responseJson: { network_id: number } = await response.json();
return responseJson.network_id;
} catch (error) {
if (!useDefaultOnError) {
throw error;
}
// log error and return default nework chain ID
console.warn(`Error fetching network chain ID from ${url}`, error);
return network.chainId;
}
}
function isNetworkCustomTestnet(network: StacksNetwork) {
return (
network.version !== TransactionVersion.Mainnet &&
new URL(network.coreApiUrl).host !== new URL(HIRO_TESTNET_DEFAULT).host
);
}
/**
* @deprecated Use the new {@link estimateTransaction} function instead.

@@ -756,2 +788,7 @@ *

// Lookup chain ID for (non-primary) testnet networks
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -1030,2 +1067,7 @@ }

// Lookup chain ID for (non-primary) testnet networks
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -1244,2 +1286,7 @@ }

// Lookup chain ID for (non-primary) testnet networks
if (isNetworkCustomTestnet(network)) {
transaction.chainId = await getNetworkChainID(network);
}
return transaction;

@@ -1246,0 +1293,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc