#### Polkadot Typed Api was moved to another repository. [polkadot-typed-api](https://www.npmjs.com/package/polkadot-typed-api) #### EigenLayer Tools were moved to another repository. [eigenlayer-tools](https://www.npmjs.com/package/eigenlayer-tools)
npm install common-crypto-tools#### Polkadot Typed Api was moved to another repository. polkadot-typed-api
#### EigenLayer Tools were moved to another repository. eigenlayer-tools
0x387...dCE0x387...dCE -> 387...dCEEthersBigNumberBigNumberShortens blockchain addresses by keeping characters at the start and end, replacing the middle with symbols.
address: The blockchain address to abbreviate.options: Config for customization:number: Sets characters to keep at start/end.Options (object): Advanced settings like size, symbol, and ignore list.#### Default
``typescript
import { abbreviateAddress } from "common-crypto-tools";
abbreviateAddress("0x1234567890abcdef1234567890abcdef");
// Output: "0x1234...cdef"
`
#### Custom Size and Symbol
`typescript`
abbreviateAddress("0x1234567890abcdef1234567890abcdef", {
size: { start: 4, end: 4 },
symbol: "*",
symbolsCount: 5,
});
// Output: "0x1234*cdef"
#### Ignore List
`typescript`
abbreviateAddress("0x1234567890abcdef1234567890abcdef", {
ignoreList: ["0x1234567890abcdef1234567890abcdef"],
});
// Output: "0x1234567890abcdef1234567890abcdef"
#### Advanced
`typescript`
abbreviateAddress("0x1234567890abcdef1234567890abcdef", {
size: [2, 6],
symbol: ".",
});
// Output: "0x12...cdef12"
The addHTMLBreaksToAddress function adds invisible HTML breaks to a string (e.g., a blockchain address) at regular intervals, making it more readable or ensuring proper wrapping in HTML contexts.
(string): The input string to format. Defaults to an empty string.
- lettersBeforeSpace (number): The number of characters between each inserted invisible space. Must be a positive number.$3
A string with invisible HTML breaks added at the specified intervals.$3
#### Default Usage
`typescript
import { addHTMLBreaksToAddress } from 'common-crypto-tools';console.log(addHTMLBreaksToAddress("0x1234567890abcdef"));
// Output: "0x1234567890abcdef"
`#### Custom Interval
`typescript
console.log(addHTMLBreaksToAddress("0x1234567890abcdef", 6));
// Output: "0x1234abcdef"
`#### Error Handling
`typescript
try {
addHTMLBreaksToAddress("0x1234567890abcdef", -1);
} catch (error) {
console.error(error.message);
// Output: "Param lettersBeforeSpace is to small: -1"
}
`removeLeading0x
Removes the 0x prefix from a string if it exists.$3
- data (string): Input string.$3
A string without the 0x prefix, or the original string if no prefix is found.$3
`typescript
removeLeading0x("0x123456"); // "123456"
removeLeading0x("123456"); // "123456"
removeLeading0x("0x"); // ""
`toBigNumber
Converts a BigNumberish value into an Ethers BigNumber instance.$3
- value (BigNumberish): The input value to convert. Can be a number, string, or other compatible type.$3
An Ethers BigNumber instance representing the input value.$3
`typescript
import { toBigNumber } from 'common-crypto-tools';// Convert number
console.log(toBigNumber(123).toString());
// Output: "123"
// Convert string
console.log(toBigNumber("456").toString());
// Output: "456"
// Convert hex string
console.log(toBigNumber("0x1a").toString());
// Output: "26"
`toBigFloat
Converts a value (BigNumber, Ethers BigNumber, or other valid input) into a BigNumber instance for consistent floating-point operations.$3
- value (BigNumber.Value | EthersBigNumber): The input value to convert. Supports BigNumber-compatible formats or Ethers BigNumber.$3
A BigNumber instance representing the input value.$3
`typescript
import { toBigFloat } from 'common-crypto-tools';
import { BigNumber as EthersBigNumber } from 'ethers';// Convert Ethers BigNumber
const ethersValue = EthersBigNumber.from("1000000000000000000");
console.log(toBigFloat(ethersValue).toString());
// Output: "1000000000000000000"
// Convert number
console.log(toBigFloat(123.456).toString());
// Output: "123.456"
// Convert string
console.log(toBigFloat("12345.6789").toString());
// Output: "12345.6789"
`explorerUrl
The
explorerUrl function generates blockchain explorer URLs for transactions, addresses, and blocks. It supports multiple blockchain networks and allows customization of the base URL and paths.$3
- Generates URLs for transactions, addresses, and blocks.
- Supports Ethereum, Arbitrum, Polygon, Binance Smart Chain, Optimism, Fantom, Avalanche, Solana, Tron, and Cosmos.
- Allows customization of the base URL and path segments.$3
#### Basic Usage
`typescript
import { explorerUrl } from 'common-crypto-tools';// Ethereum Explorer
const ethExplorer = explorerUrl("ethereum");
console.log(ethExplorer.tx("0x123")); // Output: https://etherscan.io/tx/0x123
console.log(ethExplorer.address("0xabc")); // Output: https://etherscan.io/address/0xabc
console.log(ethExplorer.block(123456)); // Output: https://etherscan.io/block/123456
// Polygon Explorer
const polygonExplorer = explorerUrl("polygon");
console.log(polygonExplorer.tx("0x456")); // Output: https://polygonscan.com/tx/0x456
`#### Customization
`typescript
// Custom Ethereum Explorer
const customEthExplorer = explorerUrl("ethereum", {
base: "https://custom.etherscan.io",
tx: "transaction",
address: "addr",
block: "blk",
});console.log(customEthExplorer.tx("0x123")); // Output: https://custom.etherscan.io/transaction/0x123
console.log(customEthExplorer.address("0xabc")); // Output: https://custom.etherscan.io/addr/0xabc
console.log(customEthExplorer.block(123456)); // Output: https://custom.etherscan.io/blk/123456
`#### Error Handling
``typescript