NibiJS - Functions
- Devnet
- IncentivizedTestnet
- Testnet
- assert
- assertExpectedError
- assertHasEventType
- assertHasMsgType
- assertValidBlock
- assertValidBlockFromJsonRpc
- bytesToHex
- chainToParts
- eventToMap
- faucetUrlFromChain
- findEvent
- fromSdkDec
- fromSdkInt
- getRegistry
- hexToBytes
- isMsgAddMarginEncodeObject
- isMsgClosePositionEncodeObject
- isMsgCreatePoolEncodeObject
- isMsgDonateToEcosystemFundEncodeObject
- isMsgExitPoolEncodeObject
- isMsgJoinPoolEncodeObject
- isMsgMultiLiquidateEncodeObject
- isMsgOpenPositionEncodeObject
- isMsgPartialCloseEncodeObject
- isMsgRemoveMarginEncodeObject
- isMsgSwapAssetsEncodeObject
- isRestEndptLive
- newCoinMapFromCoins
- newRandomWallet
- newSignerFromMnemonic
- parseError
- parseEventLogs
- queryChainIdWithRest
- setupEpochsExtension
- setupInflationExtension
- setupOracleExtension
- setupPerpExtension
- setupSpotExtension
- setupSudoExtension
- toSdkDec
- toSdkInt
- transformPool
- transformPoolParams
- useFaucet
NibiJS - Functions
Devnet
▸ Devnet(chainNumber): CustomChain
Devnet: "Chain" configuration for a Nibiru "devnet". These networks are more ephemeral than "Testnet" and used internally by the core Nibiru dev team to live-test new features before official public release.
Parameters
| Name | Type |
|---|---|
chainNumber | number |
Returns
Defined in
IncentivizedTestnet
▸ IncentivizedTestnet(chainNumber?): CustomChain
Parameters
| Name | Type | Default value |
|---|---|---|
chainNumber | number | 1 |
Returns
Deprecated
Incentivized testnet is no longer active. This variable exists for backwards compatibility, but "Testnet" should be used instead.
See
Testnet - Permanent Nibiru public test network.
Defined in
Testnet
▸ Testnet(chainNumber?): CustomChain
Testnet: "Chain" configuration for a Nibiru testnet. These are public networks that are upgraded in advance of Nibiru's mainnet network as a beta-testing environments.
For an updated list of active networks, see: TODO: Add networks link
By default, the "Testnet" function returns the permanent testnet if no arguments are passed.
Parameters
| Name | Type | Default value |
|---|---|---|
chainNumber | number | 1 |
Returns
Defined in
assert
▸ assert(condition, message?): string | boolean
Asserts that a given condition is true. If the condition evaluates to false, an "AssertionError" is thrown with an optional custom message.
Parameters
| Name | Type | Description |
|---|---|---|
condition | boolean | The condition to test. |
message? | string | Optional. A custom error message to display if the assertion fails. |
Returns
string | boolean
- Returns true if the assertion is successful.
Defined in
assertExpectedError
▸ assertExpectedError(err, okErrors): void
Asserts that the given error matches one of the expected error messages.
This function parses the error object to extract its message and checks if it includes any of the specified acceptable error messages. It sets a test expectation that the error message is contained within the list of acceptable errors.
Parameters
| Name | Type | Description |
|---|---|---|
err | unknown | The error object to be tested. |
okErrors | string[] | An array of acceptable error message strings. |
Returns
void
Defined in
assertHasEventType
▸ assertHasEventType(eventType, events): void
Asserts that an array of ABCIEvent objects contains an event with a specified type. This runs a test expectation that the specified eventType is contained in events.
Parameters
| Name | Type | Description |
|---|---|---|
eventType | string | The event type to look for in the array of events. |
events | ABCIEvent[] | An array of ABCIEvent objects to be tested. |
Returns
void
Defined in
assertHasMsgType
▸ assertHasMsgType(msgType, events): void
Asserts that a list of ABCIEvents contains a specific type of TxMsg. This TxMsg type is read from a "message" event's "action" attribute.
Parameters
| Name | Type | Description |
|---|---|---|
msgType | string | TxMsg type to look for within the event attributes. |
events | ABCIEvent[] | set of events over which we're searching. |
Returns
void
Defined in
assertValidBlock
▸ assertValidBlock(block, chain): void
assertValidBlock: Performs runtime type validation on a CometBFT "Block".
Parameters
| Name | Type |
|---|---|
block | Block |
chain | Chain |
Returns
void
Defined in
assertValidBlockFromJsonRpc
▸ assertValidBlockFromJsonRpc(blockJson): void
Validates that block queried via the JSON RPC client has the expected fields.
Parameters
| Name | Type |
|---|---|
blockJson | any |
Returns
void
Defined in
bytesToHex
▸ bytesToHex(bz): string
Converts an 8-bit byte array (Uint8Array) into a hexadecimal (hex) string.
Each 8-bit byte ranges from 0 to 255 and is represented by a 2-tuple of hex digits (0-9, A-F). Values from 0-15 (0x0 to 0xF) are indeed single-digit in hex, but in the context of hex strings, these values are padded with a leading zero to maintain a consistent two-character representation for each byte.
Thus, a byte value of 9 is represented as "09".
Parameters
| Name | Type |
|---|---|
bz | Uint8Array |
Returns
string
Defined in
chainToParts
▸ chainToParts(chain): ChainIdParts
Converts a Chain object to its constituent parts.
Parameters
| Name | Type | Description |
|---|---|---|
chain | Chain | a Chain object |
Returns
a ChainIdParts object
Defined in
eventToMap
▸ eventToMap(event): EventMap
eventToMap: Converts an ABCIEvent into an EventMap.
Parameters
| Name | Type |
|---|---|
event | ABCIEvent |
Returns
Defined in
faucetUrlFromChain
▸ faucetUrlFromChain(chain): string
Constructs a faucet URL from a Chain object.
Parameters
| Name | Type | Description |
|---|---|---|
chain | Chain | a Chain object |
Returns
string
Defined in
findEvent
▸ findEvent(events, eventType): undefined | ABCIEvent
findEvent: Filter 'events' by type. This is useful for checking if events of known type are present.
Parameters
| Name | Type |
|---|---|
events | ABCIEvent[] |
eventType | string |
Returns
undefined | ABCIEvent
Defined in
fromSdkDec
▸ fromSdkDec(sdkDec): number
fromSdkDec: Converts a string representation of the "sdk.Dec", a shorthand name for the "cosmossdk.io/math".LegacyDec type in Golang. An Sdk Dec is a decimal/float implemented by "big.Int" with 18 decimals of precision an abstraction for 18 decimals of precision big.Int.
Sdk Dec is a custom protobuf type encoded as a string. NOTE: The string for the raw protobuf value is not the human-readable one that can include decimal points and negative signs. It's actually a string holding the underlying "big.Int" value from which the concrete Dec type is created.
This is why we implement the functions fromSdkDec and toSdkDec. When 'TxMessages' include SdkDec types, they need the protobuf string form, not the human-readbale Dec.
Parameters
| Name | Type |
|---|---|
sdkDec | string |
Returns
number
See
- TxMessage // from nibijs/src/tx
- toSdkDec
Defined in
fromSdkInt
▸ fromSdkInt(intStr): number
Parameters
| Name | Type |
|---|---|
intStr | string |
Returns
number
Defined in
getRegistry
▸ getRegistry(): Registry
Returns
Registry
Defined in
hexToBytes
▸ hexToBytes(hex): Result<Uint8Array>
Converts a hexadecimal-encoded string into a Uint8Array.
The hexadecimal string must have an even length, as each byte is represented by two hex digits. Each of hex digit 2-tuples (ranging from 00 to FF) is converted to a single byte ranging from 0 to 255.
Parameters
| Name | Type | Description |
|---|---|---|
hex | string | The hexadecimal string to be decoded. If the string has an odd length or contains non-hexadecimal characters, the function returns an error wrapped in a Result object rather than throwing. |
Returns
Result<Uint8Array>
The decoded Uint8Array if successful or an error result if the input is invalid.
Example
// Successful decoding
const result = hexToBytes("7A919F2CC9A51B139444F7D8E84A46EE")
if (result.isOk()) {
console.log(result.ok) // Uint8Array of bytes
} else {
console.error(result.err) // Error
}Example
// Error handling for invalid hex string
const result = hexToBytes("7G919F")
if (result.isOk()) {
console.log(result.ok)
} else {
console.error(result.err.message)
// "HexError: non-hex characters detected in hex: 7G919F"
}Defined in
isMsgAddMarginEncodeObject
▸ isMsgAddMarginEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgClosePositionEncodeObject
▸ isMsgClosePositionEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgCreatePoolEncodeObject
▸ isMsgCreatePoolEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgDonateToEcosystemFundEncodeObject
▸ isMsgDonateToEcosystemFundEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgExitPoolEncodeObject
▸ isMsgExitPoolEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgJoinPoolEncodeObject
▸ isMsgJoinPoolEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgMultiLiquidateEncodeObject
▸ isMsgMultiLiquidateEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgOpenPositionEncodeObject
▸ isMsgOpenPositionEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgPartialCloseEncodeObject
▸ isMsgPartialCloseEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgRemoveMarginEncodeObject
▸ isMsgRemoveMarginEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isMsgSwapAssetsEncodeObject
▸ isMsgSwapAssetsEncodeObject(encodeObject): boolean
Parameters
| Name | Type |
|---|---|
encodeObject | EncodeObject |
Returns
boolean
Defined in
isRestEndptLive
▸ isRestEndptLive(chain): Promise<boolean>
isRestEndptLive: Makes a request using the chain's REST endpoint to see if the network and endpoint are active.
Parameters
| Name | Type |
|---|---|
chain | Chain |
Returns
Promise<boolean>
Defined in
newCoinMapFromCoins
▸ newCoinMapFromCoins(coins): CoinMap
Parameters
| Name | Type |
|---|---|
coins | readonly Coin[] |
Returns
Defined in
newRandomWallet
▸ newRandomWallet(length?, prefix?): Promise<DirectSecp256k1HdWallet>
Generates a new wallet with a BIP39 mnemonic of length 24.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
length? | 12 | 15 | 18 | 21 | 24 | undefined | (optional) The number of words in the mnemonic (12, 15, 18, 21 or 24). |
prefix | BECH32_PREFIX | BECH32_PREFIX.ADDR | (optional) Bech32 address prefix. Defaults to "nibi". |
Returns
Promise<DirectSecp256k1HdWallet>
A wallet for protobuf based signing using SIGN_MODE_DIRECT.
Export
Defined in
newSignerFromMnemonic
▸ newSignerFromMnemonic(mnemonic, prefix?): Promise<DirectSecp256k1HdWallet>
Creates a wallet from the given BIP39 mnemonic.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
mnemonic | string | undefined | |
prefix | BECH32_PREFIX | BECH32_PREFIX.ADDR | (optional) Bech32 address prefix. Defaults to "nibi". |
Returns
Promise<DirectSecp256k1HdWallet>
A wallet for protobuf based signing using SIGN_MODE_DIRECT
Export
Defined in
parseError
▸ parseError(err): Error
parseError: Guarantees runtime strong error typing since this isn't guaranteed in JS by default. The error that comes out of a try-catch may not have type "Error" since it's perfectly valid to throw strings or undefined.
Parameters
| Name | Type |
|---|---|
err | any |
Returns
Error
Defined in
parseEventLogs
▸ parseEventLogs(txResp): EventMap[]
parseEventLogs: Returns a mutable and typed version of the events payload from a tx response.
Parameters
| Name | Type |
|---|---|
txResp | DeliverTxResponse |
Returns
EventMap[]
Example
let txResp: DeliverTxResponse // assume this is given
const eventLogs = parseEventLogs(txResp)Defined in
queryChainIdWithRest
▸ queryChainIdWithRest(chain): Promise<Result<string>>
Parameters
| Name | Type |
|---|---|
chain | Chain |
Returns
Promise<Result<string>>
Defined in
setupEpochsExtension
▸ setupEpochsExtension(base): EpochsExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
setupInflationExtension
▸ setupInflationExtension(base): InflationExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
setupOracleExtension
▸ setupOracleExtension(base): OracleExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
setupPerpExtension
▸ setupPerpExtension(base): PerpExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
setupSpotExtension
▸ setupSpotExtension(base): SpotExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
setupSudoExtension
▸ setupSudoExtension(base): SudoExtension
Parameters
| Name | Type |
|---|---|
base | QueryClient |
Returns
Defined in
toSdkDec
▸ toSdkDec(dec): string
toSdkDec converts the input float string to an sdk.Dec. The maximum number of decimal places for an sdk.Dec is 18. NOTE: An error is console loggedd if more decimal digits are provided than the precision, 18.
ref: Reimplementation of cosmos-sdk/types/decimal.go
Valid inputs must come in the form: (-) integer digits (.) fractional digits Examples of acceptable input include: -123.456 456.7890 345 -456789
CONTRACT - This function does not mutate the input str.
Parameters
| Name | Type |
|---|---|
dec | string |
Returns
string
- Protobuf string for an sdk.Dec, which is represented by its underlying "big.Int".
See
fromSdkDec - The inverse of this function that converts an sdk.Dec protobuf string into a number.
Export
Defined in
toSdkInt
▸ toSdkInt(i): string
Parameters
| Name | Type |
|---|---|
i | number |
Returns
string
Defined in
transformPool
▸ transformPool(p?): undefined | Pool
Parameters
| Name | Type |
|---|---|
p? | Pool |
Returns
undefined | Pool
Defined in
transformPoolParams
▸ transformPoolParams(pp?): undefined | PoolParams
Parameters
| Name | Type |
|---|---|
pp? | PoolParams |
Returns
undefined | PoolParams
Defined in
useFaucet
▸ useFaucet(«destructured»): Promise<Response | undefined>
Sends 11 NIBI, 100 NUSD, and 100 USDT to the given address from the testnet faucet.
Parameters
| Name | Type |
|---|---|
«destructured» | Object |
› address | string |
› amts? | Object |
› amts.nibi | number |
› amts.nusd | number |
› amts.usdt | number |
› chain | Chain |
› grecaptcha | string |
Returns
Promise<Response | undefined>