### Install Initia.js SDK via npm Source: https://github.com/initia-labs/initia.js/blob/main/README.md This command installs the Initia.js SDK package using npm, making it available for use in JavaScript/TypeScript projects. It's the first step to integrate Initia.js into your development environment. ```bash npm install @initia/initia.js ``` -------------------------------- ### Perform Binary Canonical Serialization (BCS) Operations Source: https://github.com/initia-labs/initia.js/blob/main/README.md Shows examples of using the `bcs` utility for serializing and deserializing values according to the Binary Canonical Serialization (BCS) standard. It covers `u64` types, vectors, and optional values, demonstrating conversion to and from Base64 for on-chain compatibility. ```typescript import { bcs } from '@initia/initia.js' // serialize, serialize value to BCS and encode it to base64 const serializedU64 = bcs .u64() // type .serialize(1234) // value .toBase64() // deserialize const deserializedU64 = bcs .u64() // type .parse(Uint8Array.from(Buffer.from(serializedU64, 'base64'))) // vector const serializedVector = bcs .vector(bcs.u64()) .serialize([123, 456, 789]) .toBase64() // option const serializedSome = bcs.option(bcs.u64()).serialize(123) const serializedNone = bcs.option(bcs.u64()).serialize(null) ``` -------------------------------- ### Create MsgExecute Transaction for Move Contract Source: https://github.com/initia-labs/initia.js/blob/main/README.md Provides an example of creating a `MsgExecute` object to call a Move contract function. It includes specifying the module owner, name, function, type arguments, and BCS-encoded arguments for execution. ```TypeScript import { MsgExecute } from '@initia/initia.js' const msg = new MsgExecute( 'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address '0x1', // owner of the module 'dex', // name of the module 'swap_script', // function name [], // type arguments [ bcs.address().serialize('0x2').toBase64(), // arguments, BCS-encoded bcs.address().serialize('0x3').toBase64(), // arguments, BCS-encoded bcs.u64().serialize(10000).toBase64() // arguments, BCS-encoded ] ) ``` -------------------------------- ### Create and Sign Transaction with Wallet Source: https://github.com/initia-labs/initia.js/blob/main/README.md Demonstrates the process of initializing a wallet with a mnemonic key and REST client, then creating and signing a transaction containing a `MsgSend` message. It highlights setting up the REST client with chain ID, gas prices, and gas adjustment for transaction preparation. ```TypeScript import { Wallet, RESTClient, MnemonicKey, MsgSend } from '@initia/initia.js' const key = new MnemonicKey({ mnemonic: 'moral wise tape glance grit gentle movie doll omit you pet soon enter year funny gauge digital supply cereal city ring egg repair coyote', }) const rest = new RESTClient('https://rest.testnet.initia.xyz', { chainId: 'initiation-2', gasPrices: '0.15uinit', // default gas prices gasAdjustment: '1.75', // default gas adjustment for fee estimation }) const wallet = new Wallet(rest, key) const sendMsg = new MsgSend( 'init14l3c2vxrdvu6y0sqykppey930s4kufsvt97aeu', // sender address 'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // recipient address '1000uinit', // send amount ) const signedTx = await wallet.createAndSignTx({ msgs: [sendMsg], memo: 'sample memo', }) ``` -------------------------------- ### Initialize Initia.js REST Client Source: https://github.com/initia-labs/initia.js/blob/main/README.md Demonstrates how to import and instantiate the `RESTClient` class to interact with the Initia blockchain. It shows configuration options for the chain ID, default gas prices, and gas adjustment for fee estimation, which are crucial for transaction processing. ```typescript import { RESTClient } from '@initia/initia.js' const rest = new RESTClient('https://rest.testnet.initia.xyz', { chainId: 'initiation-2', gasPrices: '0.15uinit', // default gas prices gasAdjustment: '1.75', // default gas adjustment for fee estimation }) ``` -------------------------------- ### Initia.js Transaction Broadcasting API Source: https://github.com/initia-labs/initia.js/blob/main/README.md API methods for creating, signing, and broadcasting transactions to the blockchain, enabling interaction with the network. ```APIDOC createAndSignTx(): Create a wallet and sign transaction. broadcast(): Sends your transaction to the blockchain. ``` -------------------------------- ### Create a Mnemonic Key for Transaction Signing Source: https://github.com/initia-labs/initia.js/blob/main/README.md Illustrates how to create a `MnemonicKey` instance, which is used for transaction signing and address derivation. It highlights optional parameters for providing a mnemonic phrase, BIP44 account number, index, and coin type, allowing for flexible key generation. ```typescript import { MnemonicKey } from '@initia/initia.js' const key = new MnemonicKey({ mnemonic: 'bird upset ... evil cigar', // (optional) if null, generate a new Mnemonic key account: 0, // (optional) BIP44 account number. default = 0 index: 0, // (optional) BIP44 index number. default = 0 coinType: 60, // (optional) BIP44 coinType. default = 60 }) ``` -------------------------------- ### Initia.js Query API Source: https://github.com/initia-labs/initia.js/blob/main/README.md API methods for querying blockchain data, including account balances and Move view function results, allowing retrieval of on-chain information. ```APIDOC balance(): Query the balance of the account. viewfunction(): Obtain the return values of a Move view function. ``` -------------------------------- ### Query Move View Function Source: https://github.com/initia-labs/initia.js/blob/main/README.md Demonstrates how to obtain return values from a Move view function using the `RESTClient`'s `move.viewFunction` method. It requires specifying the module details and BCS-encoded arguments to execute the view function. ```TypeScript const res = await rest.move.viewFunction( '0x1', // owner of the module 'dex', // name of the module 'get_swap_simulation', // function name [], // type arguments [ bcs.address().serialize('0x2').toBase64(), // arguments, BCS-encoded bcs.address().serialize('0x3').toBase64(), // arguments, BCS-encoded bcs.u64().serialize(10000).toBase64() // arguments, BCS-encoded ] ) ``` -------------------------------- ### Query Account Balance Source: https://github.com/initia-labs/initia.js/blob/main/README.md Illustrates how to query the balance of a specific account using the `RESTClient`'s `bank.balance` method. This retrieves the current coin balances for the given address from the blockchain. ```TypeScript const balances = await rest.bank.balance('init14l3c2vxrdvu6y0sqykppey930s4kufsvt97aeu') ``` -------------------------------- ### LedgerKey and LedgerApp Class Structure Source: https://github.com/initia-labs/initia.js/blob/main/src/key/ledger/readme.md Defines the inheritance and dependencies for the `LedgerKey` class and its specialized `LedgerApp` implementations, `EthereumApp` and `CosmosApp`, indicating their reliance on specific Ledger hardware application libraries for their functionality. ```APIDOC LedgerKey: extends: Key Apps: - EthereumApp - CosmosApp EthereumApp: extends: LedgerApp has: - Eth from @ledgerhq/hw-app-eth CosmosApp: extends: LedgerApp has: - Cosmos from @zondax/ledger-cosmos-js ``` -------------------------------- ### Create MsgSend Transaction Source: https://github.com/initia-labs/initia.js/blob/main/README.md Demonstrates how to create a `MsgSend` object to send coins between two addresses using the `initia.js` library. This message specifies the sender, recipient, and amount for a transfer. ```TypeScript import { MsgSend } from '@initia/initia.js' const msg = new MsgSend( 'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // sender address 'init18sj3x80fdjc6gzfvwl7lf8sxcvuvqjpvcmp6np', // recipient address '1000uinit', // send amount ) ``` -------------------------------- ### Initia.js Message Types (Msgs) API Source: https://github.com/initia-labs/initia.js/blob/main/README.md Overview of core message types in `initia.js` that trigger state transitions when wrapped in transactions. These messages define the actions to be performed on the blockchain. ```APIDOC MsgSend(): Send coins to others. MsgDelegate(): Delegate governance coin to validators (staking). MsgUndelegate(): Undelegate governance coin from validators (unstaking). MsgExecute(): Execute move contract function. ``` -------------------------------- ### Broadcast Signed Transaction to Blockchain Source: https://github.com/initia-labs/initia.js/blob/main/README.md Shows how to broadcast a previously signed transaction to the blockchain using the `RESTClient`'s `tx.broadcast` method. This action sends the transaction for inclusion in a block, making the state changes permanent. ```TypeScript const broadcastResult = await rest.tx.broadcast(signedTx) ``` -------------------------------- ### Create MsgUndelegate Transaction Source: https://github.com/initia-labs/initia.js/blob/main/README.md Shows how to construct a `MsgUndelegate` object to unstake governance coins from a validator. This message is used for undelegating previously staked funds, making them available again. ```TypeScript import { MsgUndelegate } from '@initia/initia.js' const msg = new MsgUndelegate( 'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address 'initvaloper14qekdkj2nmmwea4ufg9n002a3pud23y8l3ep5z', // validator's operator (valoper) address '100000uinit', // undelegate amount ) ``` -------------------------------- ### Create MsgDelegate Transaction Source: https://github.com/initia-labs/initia.js/blob/main/README.md Illustrates the creation of a `MsgDelegate` object for staking governance coins to a validator. This message is used for delegating funds within the Initia network to participate in staking. ```TypeScript import { MsgDelegate } from '@initia/initia.js' const msg = new MsgDelegate( 'init1kdwzpz3wzvpdj90gtga4fw5zm9tk4cyrgnjauu', // delegator address 'initvaloper14qekdkj2nmmwea4ufg9n002a3pud23y8l3ep5z', // validator's operator (valoper) address '100000uinit', // delegate amount ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.