import { PrivateKey } from '@klever/connect-crypto'; import { Transaction as Transaction$1, ITransaction } from '@klever/connect-encoding'; import { AmountLike, IProvider, ContractRequestData, TransferRequest, FreezeRequest, UnfreezeRequest, DelegateRequest, UndelegateRequest, WithdrawRequest, ClaimRequest, CreateAssetRequest, CreateValidatorRequest, VoteRequest, SmartContractRequest, BuildTransactionRequest, AssetTriggerRequest, ProposalRequest, SetAccountNameRequest } from '@klever/connect-provider'; export { AmountLike, AssetTriggerRequest, BuildTransactionRequest, BuyRequest, CancelMarketOrderRequest, ClaimRequest, ConfigITORequest, ConfigMarketplaceRequest, ContractRequestData, CreateAssetRequest, CreateMarketplaceRequest, CreateValidatorRequest, DelegateRequest, DepositRequest, FreezeRequest, ITOTriggerRequest, ProposalRequest, SellRequest, SetAccountNameRequest, SetITOPricesRequest, SmartContractRequest, TransferRequest, UndelegateRequest, UnfreezeRequest, UnjailRequest, UpdateAccountPermissionRequest, ValidatorConfigRequest, VoteRequest, WithdrawRequest } from '@klever/connect-provider'; export { ContractType } from '@klever/connect-core'; /** * Transaction class representing a Klever blockchain transaction * Extends the protobuf Transaction class with convenience methods * * This class wraps the proto-generated Transaction and provides: * - Easy signing with private keys * - Serialization to bytes/hex * - Fee calculations * - Transaction state management * * This is a pure data class - no network dependencies. * Use provider.sendRawTransaction(tx.toHex()) to broadcast. */ declare class Transaction extends Transaction$1 { private hash?; /** * Create a Transaction from proto-generated transaction data * @param data - Proto transaction data (from node or local build) */ constructor(data?: ITransaction); /** * Get raw proto bytes for the transaction * This is what gets signed and broadcast to the network * * @returns Proto bytes as Uint8Array * * @example * ```typescript * const tx = new Transaction(txData) * const bytes = tx.toBytes() * // bytes: Uint8Array [10, 32, 65, ...] * // Use for signing or network transmission * ``` */ toBytes(): Uint8Array; /** * Get proto bytes as hex string * Useful for broadcasting to node via HTTP or storing in databases * * @returns Hex encoded proto bytes (without 0x prefix) * * @example * ```typescript * const tx = new Transaction(txData) * await tx.sign(privateKey) * const hex = tx.toHex() * // hex: "0a20418f2b3c..." * * // Broadcast to network * const hash = await provider.sendRawTransaction(hex) * ``` */ toHex(): string; toJSON(): { [k: string]: unknown; }; /** * Sign the transaction with a private key * Signs the transaction hash (blake2b of RawData) * @param privateKey - Private key to sign with * @returns This transaction instance with signature added * * @example * ```typescript * const tx = new Transaction(txData) * await tx.sign(privateKey) * // tx now has Signature field populated * ``` */ sign(privateKey: PrivateKey): Promise; /** * Check if transaction is signed * Verifies whether the transaction has been signed and is ready for broadcast * * @returns true if transaction has at least one signature, false otherwise * * @example * ```typescript * const tx = new Transaction(txData) * console.log(tx.isSigned()) // false * * await tx.sign(privateKey) * console.log(tx.isSigned()) // true * * // Only broadcast if signed * if (tx.isSigned()) { * await provider.sendRawTransaction(tx.toHex()) * } * ``` */ isSigned(): boolean; /** * Get total fee (KAppFee + BandwidthFee) * Returns the combined fee for the transaction in smallest KLV units * * @returns Total fee amount in KLV smallest units (1 KLV = 1,000,000 units) * * @example * ```typescript * const tx = new Transaction(txData) * const totalFee = tx.getTotalFee() * console.log(`Total fee: ${totalFee} units`) // e.g., "600000 units" * * // Convert to human-readable KLV * const feeInKLV = Number(totalFee) / 1_000_000 * console.log(`Fee: ${feeInKLV} KLV`) // e.g., "0.6 KLV" * ``` */ getTotalFee(): bigint; /** * Get the transaction hash bytes * Computes blake2b hash of the RawData proto bytes * @returns Transaction hash as Uint8Array * * @example * ```typescript * const tx = new Transaction(txData) * const hashBytes = tx.getHashBytes() * // Use for signing or other operations * ``` */ getHashBytes(): Uint8Array; /** * Get the transaction hash * Computes blake2b hash of the RawData proto bytes * @returns Transaction hash as hex string * * @example * ```typescript * const tx = new Transaction(txData) * const hash = tx.getHash() * // hash: "a3f2e8d9..." * ``` */ getHash(): string; /** * Create a Transaction from hex-encoded proto bytes * Decodes a hex string back into a Transaction object * * @param hex - Hex string of proto-encoded transaction (with or without 0x prefix) * @returns Transaction instance * * @example * ```typescript * // Decode hex string from storage or API * const hex = "0a20418f2b3c..." * const tx = Transaction.fromHex(hex) * * // Verify signature * console.log(tx.isSigned()) // true or false * * // Get transaction hash * console.log(tx.getHash()) * ``` */ static fromHex(hex: string): Transaction; /** * Create a Transaction from raw proto bytes * Decodes protobuf bytes back into a Transaction object * * @param bytes - Proto-encoded transaction bytes * @returns Transaction instance * * @example * ```typescript * // Decode bytes from storage or network * const bytes = new Uint8Array([10, 32, 65, ...]) * const tx = Transaction.fromBytes(bytes) * * // Verify and use * console.log(tx.getHash()) * console.log(tx.isSigned()) * ``` */ static fromBytes(bytes: Uint8Array): Transaction; /** * Create a Transaction from a plain JSON object (from API) * Properly converts base64 strings to Uint8Array for proto fields. * This is typically used when receiving transaction data from the node's API. * * @param obj - Plain object with base64-encoded byte fields * @returns Transaction instance * * @example * ```typescript * // Response from node's /transaction/build endpoint * const response = await fetch('/transaction/build', { * method: 'POST', * body: JSON.stringify(buildRequest) * }) * const data = await response.json() * * // Convert API response to Transaction * const tx = Transaction.fromObject(data.result) * * // Sign and broadcast * await tx.sign(privateKey) * await provider.sendRawTransaction(tx.toHex()) * ``` */ static fromObject(obj: { [k: string]: unknown; }): Transaction; /** * Create a new Transaction from an existing Transaction * Creates a deep copy of the transaction * * @param tx - Existing Transaction instance * @returns New Transaction instance * * @example * ```typescript * const originalTx = new Transaction(txData) * const copiedTx = Transaction.fromTransaction(originalTx) * * // Modifications to copiedTx won't affect originalTx * await copiedTx.sign(privateKey) * ``` */ static fromTransaction(tx: Transaction): Transaction; } /** * Build call options * All fields are optional - will use builder's state if not provided */ interface BuildCallOptions { /** Value to send with transaction (e.g., { KLV: parseKLV('1') }) */ value?: Record; /** Chain ID for offline transaction building */ chainId?: string; /** Sender address */ sender?: string; /** Nonce for offline transaction building */ nonce?: number; /** Fees for offline transaction building */ fees?: { kAppFee: number; bandwidthFee: number; }; /** KDA fee for offline transaction building */ kdaFee?: { kda: string; amount: AmountLike; }; /** Permission ID for the transaction */ permissionId?: number; /** Transaction data (for smart contract calls) */ data?: string[]; } /** * TransactionBuilder - Fluent API for building Klever blockchain transactions * * Supports three build modes: * 1. buildRequest() - Create request object for node endpoint * 2. buildProto(options) - Build proto offline (client-side) * 3. build() - Build using node endpoint (requires provider) * * @example * ```typescript * // Chainable building and signing * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .build() * * await tx.sign(privateKey) * const hash = await provider.sendRawTransaction(tx.toHex()) * * // Node-assisted building * const provider = new KleverProvider({ network: 'mainnet' }) * const tx = await new TransactionBuilder(provider) * .sender('klv1...') * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .build() * * // Offline building * const tx = new TransactionBuilder() * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .buildProto({ * sender: 'klv1...', * nonce: 123, * fees: { kAppFee: 500000, bandwidthFee: 100000 } * }) * ``` */ declare class TransactionBuilder { private provider?; private contracts; private _chainId?; private _sender?; private _nonce?; private _kdaFee?; private _permissionId?; private _data?; constructor(provider?: IProvider | undefined); /** * Create a new TransactionBuilder with provider (static factory) * Provides a cleaner API for chainable transaction building * * @example * ```typescript * const tx = await TransactionBuilder.create(provider) * .sender(address) * .transfer({ receiver, amount }) * .build() * * await tx.sign(privateKey) * const hash = await provider.sendRawTransaction(tx.toHex()) * ``` */ static create(provider?: IProvider): TransactionBuilder; /** * Get the provider instance */ getProvider(): IProvider | undefined; /** * Set the provider instance */ setProvider(provider: IProvider): this; /** * Set chain ID (overrides provider's network if set) * The chain ID identifies which Klever network to use (e.g., "100" for mainnet) * * @param chainId - Chain ID string (e.g., "100" for mainnet, "101" for testnet) * @returns This builder instance for chaining * * @example * ```typescript * const tx = TransactionBuilder.create() * .setChainId('100') * .sender('klv1...') * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .buildProto({ nonce: 1, fees: { kAppFee: 500000, bandwidthFee: 100000 } }) * ``` */ setChainId(chainId: string): this; /** * Set sender address for the transaction * * @param address - Bech32 encoded Klever address (e.g., "klv1...") * @returns This builder instance for chaining * @throws {ValidationError} If address format is invalid * * @example * ```typescript * const tx = await TransactionBuilder.create(provider) * .sender('klv1fpwjz234gy8aaae3gx0e8q9f52vymzzn3z5q0s5h60pvktzx0n0qwvtux5') * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .build() * ``` */ sender(address: string): this; /** * Set nonce manually for offline transaction building * The nonce is a sequential counter that prevents transaction replay attacks. * Each account has its own nonce that increments with every transaction. * * **When to use:** * - Offline transaction building (required with buildProto()) * - Manual nonce management for batch transactions * - Testing or debugging specific scenarios * * **Getting current nonce:** * Use `provider.getAccount(address)` to get the current nonce from the network * * @param nonce - Transaction nonce (must be non-negative) * @returns This builder instance for chaining * @throws {ValidationError} If nonce is negative * * @example * ```typescript * // Manual nonce for offline building * const tx = TransactionBuilder.create() * .sender('klv1...') * .nonce(123) * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .buildProto({ * chainId: '100', * fees: { kAppFee: 500000, bandwidthFee: 100000 } * }) * * // Get nonce from provider first * const account = await provider.getAccount('klv1...') * const tx = TransactionBuilder.create() * .sender('klv1...') * .nonce(account.nonce) * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .buildProto({ chainId: '100', fees: { kAppFee: 500000, bandwidthFee: 100000 } }) * ``` */ nonce(nonce: number): this; /** * Set KDA fee to pay transaction fees in a custom KDA asset instead of KLV * By default, transactions pay fees in KLV (kAppFee + bandwidthFee). * This method allows paying fees in a different asset. * * **Important:** * - Cannot use 'KLV' as kdaFee (KLV is the default fee asset) * - The asset must support being used as a fee payment option * * @param fee - KDA fee configuration * @param fee.kda - Asset ID to use for fee payment (cannot be 'KLV') * @param fee.amount - Fee amount in smallest units of the KDA asset * @returns This builder instance for chaining * @throws {ValidationError} If kda is 'KLV' or amount is negative * * @example * ```typescript * // Pay fees in custom token instead of KLV * const tx = TransactionBuilder.create() * .sender('klv1...') * .kdaFee({ kda: 'MYTOKEN-ABCD', amount: '1000000' }) * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .buildProto({ * nonce: 1, * chainId: '100', * }) * ``` */ kdaFee(fee: { kda: string; amount: AmountLike; }): this; /** * Set permission ID for multi-signature transactions * Permission IDs enable complex account structures with multiple signers and permissions. * * **Use cases:** * - Multi-signature wallets requiring multiple approvals * - Corporate accounts with different permission levels * - Smart contract interactions with specific permissions * * @param id - Permission ID number * @returns This builder instance for chaining * * @example * ```typescript * // Transaction requiring specific permission * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .permissionId(2) * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .build() * ``` */ permissionId(id: number): this; /** * Set transaction data for smart contract calls * Data is used primarily for smart contract interactions, where it contains: * - Function name (first element) * - Function arguments (remaining elements) * * **Important:** * - Data is automatically base64 encoded when building with buildRequest() * - For offline building with buildProto(), provide UTF-8 strings * * @param data - Array of strings containing function name and arguments * @returns This builder instance for chaining * * @example * ```typescript * // Smart contract call with arguments * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .smartContract({ address: 'klv1contract...', scType: 0 }) * .data(['transfer', 'klv1receiver...', '1000000']) * .build() * * // Multiple data fields * const tx = TransactionBuilder.create() * .sender('klv1...') * .smartContract({ address: 'klv1contract...', scType: 0 }) * .data(['functionName', 'arg1', 'arg2', 'arg3']) * .buildProto({ nonce: 1, chainId: '100', fees: { kAppFee: 500000, bandwidthFee: 100000 } }) * ``` */ data(data: string[]): this; /** * Add multiple build options at once * Convenience method to set multiple builder options in a single call. * This is particularly useful when working with smart contracts or offline building. * * **Note:** The `value` option is not supported here - set callValue directly in smartContract() * * @param options - Build options object * @param options.sender - Sender's bech32 address * @param options.nonce - Transaction nonce * @param options.kdaFee - KDA fee configuration * @param options.permissionId - Permission ID * @param options.data - Transaction data array * @param options.chainId - Chain ID * @param options.fees - Fee amounts (kAppFee and bandwidthFee) - currently not implemented * @returns This builder instance for chaining * * @example * ```typescript * // Set multiple options at once * const tx = TransactionBuilder.create() * .transfer({ receiver: 'klv1...', amount: '1000000' }) * .callOptions({ * sender: 'klv1...', * nonce: 123, * chainId: '100', * permissionId: 1 * }) * .buildProto({ fees: { kAppFee: 500000, bandwidthFee: 100000 } }) * ``` */ callOptions(options: BuildCallOptions): this; /** * Add a contract using ContractRequestData * Routes to the appropriate builder method based on contractType. * This is a generic method that automatically calls the correct specialized method. * * **Contract Types:** * - 0: Transfer * - 1: CreateAsset * - 2: CreateValidator * - 4: Freeze * - 5: Unfreeze * - 6: Delegate * - 7: Undelegate * - 8: Withdraw * - 9: Claim * - 14: Vote * - 63: SmartContract * * @param contract - Contract request data with contractType * @returns This builder instance for chaining * * @example * ```typescript * // Add transfer contract directly * builder.addContract({ * contractType: 0, * receiver: 'klv1...', * amount: 1000000 * }) * * // Add freeze contract * builder.addContract({ * contractType: 4, * amount: 5000000, * kda: 'KLV' * }) * ``` */ addContract(contract: ContractRequestData): this; /** * Add transfer contract to send KLV or KDA assets * * @param params - Transfer parameters * @param params.receiver - Recipient's bech32 address * @param params.amount - Amount to transfer in smallest units (e.g., 1000000 = 1 KLV) * @param params.kda - Optional asset ID to transfer (defaults to KLV if not specified) * @param params.kdaRoyalties - Optional KDA royalties amount * @param params.klvRoyalties - Optional KLV royalties amount * @returns This builder instance for chaining * @throws {ValidationError} If receiver address is invalid or amount is not positive * * @example * ```typescript * // Transfer KLV * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .transfer({ * receiver: 'klv1abc123...', * amount: '1000000' // 1 KLV * }) * .build() * * // Transfer custom KDA token * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .transfer({ * receiver: 'klv1abc123...', * amount: '5000000', * kda: 'MYTOKEN-ABCD' * }) * .build() * * // Transfer with royalties (for NFTs) * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .transfer({ * receiver: 'klv1abc123...', * amount: '1', * kda: 'NFT-COLLECTION/NONCE-1', * kdaRoyalties: '100000', * klvRoyalties: '50000' * }) * .build() * ``` */ transfer(params: TransferRequest): this; /** * Add freeze (stake) contract to lock KLV or KDA assets * Freezing creates a bucket that can be delegated to validators or used for governance * * @param params - Freeze parameters * @param params.amount - Amount to freeze in smallest units * @param params.kda - Optional asset ID to freeze (defaults to KLV if not specified) * @returns This builder instance for chaining * @throws {ValidationError} If amount is not positive * * @example * ```typescript * // Freeze KLV for staking * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .freeze({ * amount: '5000000' // 5 KLV * }) * .build() * * // Freeze custom KDA token * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .freeze({ * amount: '1000000', * kda: 'MYTOKEN-ABCD' * }) * .build() * ``` */ freeze(params: FreezeRequest): this; /** * Add unfreeze (unstake) contract to unlock frozen assets * Unfreezing initiates the unlocking process - assets become available after the unlock period * * @param params - Unfreeze parameters * @param params.kda - Asset ID to unfreeze (required) * @param params.bucketId - Bucket ID to unfreeze (required for KLV, optional for other assets) * @returns This builder instance for chaining * @throws {ValidationError} If kda parameter is missing * * @example * ```typescript * // Unfreeze KLV bucket * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .unfreeze({ * kda: 'KLV', * bucketId: 'bucket-hash-123' * }) * .build() * * // Unfreeze custom KDA token * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .unfreeze({ * kda: 'MYTOKEN-ABCD' * }) * .build() * ``` */ unfreeze(params: UnfreezeRequest): this; /** * Add delegate contract to assign a frozen bucket to a validator * Delegation allows validators to use your staked KLV for consensus and earn rewards * * @param params - Delegate parameters * @param params.receiver - Validator's bech32 address to delegate to * @param params.bucketId - Optional bucket ID to delegate (if not specified, delegates all available buckets) * @returns This builder instance for chaining * @throws {ValidationError} If validator address is invalid * * @example * ```typescript * // Delegate specific bucket to validator * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .delegate({ * receiver: 'klv1validator123...', * bucketId: 'bucket-hash-123' * }) * .build() * * // Delegate all available buckets * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .delegate({ * receiver: 'klv1validator123...' * }) * .build() * ``` */ delegate(params: DelegateRequest): this; /** * Add undelegate contract to remove delegation from a validator * Undelegation returns the bucket to your control but keeps it frozen * * @param params - Undelegate parameters * @param params.bucketId - Bucket ID to undelegate (required) * @returns This builder instance for chaining * @throws {ValidationError} If bucketId is missing * * @example * ```typescript * // Undelegate bucket from validator * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .undelegate({ * bucketId: 'bucket-hash-123' * }) * .build() * ``` */ undelegate(params: UndelegateRequest): this; /** * Add withdraw contract to retrieve available funds * Used to withdraw staking rewards, unlocked frozen assets, or other withdrawable amounts * * @param params - Withdraw parameters * @param params.withdrawType - Type of withdrawal (0 = staking, 1 = FPR, etc.) * @param params.kda - Optional asset ID to withdraw * @param params.amount - Optional specific amount to withdraw * @param params.currencyID - Optional currency ID for cross-currency withdrawals * @returns This builder instance for chaining * * @example * ```typescript * // Withdraw staking rewards * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .withdraw({ * withdrawType: 0 // Staking rewards * }) * .build() * * // Withdraw specific KDA amount * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .withdraw({ * withdrawType: 0, * kda: 'MYTOKEN-ABCD', * amount: '1000000' * }) * .build() * ``` */ withdraw(params: WithdrawRequest): this; /** * Add claim contract to claim rewards or allocations * Used for claiming staking rewards, airdrops, or other claimable amounts * * @param params - Claim parameters * @param params.claimType - Type of claim (0 = staking rewards, 1 = market rewards, etc.) * @param params.id - Optional claim ID for specific claims * @returns This builder instance for chaining * * @example * ```typescript * // Claim staking rewards * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .claim({ * claimType: 0 // Staking rewards * }) * .build() * * // Claim specific allocation * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .claim({ * claimType: 1, * id: 'allocation-id-123' * }) * .build() * ``` */ claim(params: ClaimRequest): this; /** * Add create asset contract to create a new token or NFT collection * Creates fungible tokens (FTs), non-fungible tokens (NFTs), or other asset types * * @param params - Asset creation parameters * @param params.type - Asset type (0 = Fungible Token, 1 = NFT, etc.) * @param params.name - Full name of the asset * @param params.ticker - Short ticker symbol * @param params.ownerAddress - Owner's bech32 address * @param params.precision - Number of decimal places (0 for NFTs) * @param params.maxSupply - Maximum supply in smallest units * @param params.initialSupply - Optional initial supply to mint * @param params.properties - Optional asset properties (mintable, burnable, etc.) * @param params.royalties - Optional royalty configuration (for NFTs) * @returns This builder instance for chaining * * @example * ```typescript * // Create fungible token * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .createAsset({ * type: 0, * name: 'My Token', * ticker: 'MTK', * ownerAddress: 'klv1...', * precision: 6, * maxSupply: '1000000000000', * initialSupply: '100000000000' * }) * .build() * * // Create NFT collection * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .createAsset({ * type: 1, * name: 'My NFT Collection', * ticker: 'MYNFT', * ownerAddress: 'klv1...', * precision: 0, * maxSupply: 0, * royalties: { address: 'klv1...', percentage: 5 } * }) * .build() * ``` */ createAsset(params: CreateAssetRequest): this; /** * Add create validator contract to register a new validator node * Validators participate in consensus and earn rewards for securing the network * * @param params - Validator creation parameters * @param params.blsPublicKey - BLS public key for validator signing * @param params.ownerAddress - Owner's bech32 address * @param params.commission - Commission rate percentage (e.g., 10 for 10%) * @param params.canDelegate - Whether delegators can stake to this validator * @param params.rewardAddress - Optional address to receive rewards * @param params.maxDelegationAmount - Optional maximum delegation amount * @param params.name - Optional validator name * @param params.logo - Optional logo URI * @param params.uris - Optional additional URIs (website, social media, etc.) * @returns This builder instance for chaining * * @example * ```typescript * // Create validator node * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .createValidator({ * blsPublicKey: '0xabcd1234...', * ownerAddress: 'klv1...', * commission: 10, // 10% commission * canDelegate: true, * name: 'My Validator', * logo: 'https://example.com/logo.png', * uris: { * website: 'https://validator.example.com', * twitter: 'https://twitter.com/myvalidator' * } * }) * .build() * ``` */ createValidator(params: CreateValidatorRequest): this; /** * Add vote contract to participate in governance proposals * Voting allows token holders to participate in network governance decisions * * @param params - Vote parameters * @param params.proposalId - ID of the proposal to vote on * @param params.type - Vote type (0 = abstain, 1 = yes, 2 = no) * @param params.amount - Optional stake amount to use for voting weight * @returns This builder instance for chaining * * @example * ```typescript * // Vote yes on proposal * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .vote({ * proposalId: 5, * type: 1, // Yes * amount: '1000000' // Optional voting weight * }) * .build() * * // Vote no on proposal * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .vote({ * proposalId: 5, * type: 2 // No * }) * .build() * ``` */ vote(params: VoteRequest): this; /** * Add smart contract call to interact with deployed contracts * Enables calling functions on smart contracts deployed on the Klever blockchain * * **Contract Call Types (scType):** * - 0: Invoke contract function * - 1: Deploy contract * - 2: Upgrade contract * * **Important:** * - Use `.data()` to specify function name and arguments * - callValue allows sending KLV or KDA tokens with the call * - Invoke and upgrade require a valid contract address * - Deploy must not include an address * * @param params - Smart contract parameters * @param params.address - Required contract bech32 address for invoke/upgrade; forbidden for deploy * @param params.scType - Contract call type (0 = invoke, 1 = deploy, 2 = upgrade) * @param params.callValue - Optional amounts to send (e.g., { KLV: '1000000' }) * @returns This builder instance for chaining * @throws {ValidationError} If scType is unsupported * @throws {ValidationError} If invoke/upgrade is missing a contract address * @throws {ValidationError} If deploy includes a contract address * @throws {ValidationError} If contract address format is invalid * * @example * ```typescript * // Invoke contract function * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .smartContract({ * address: 'klv1contract...', * scType: 0, // Invoke * callValue: { KLV: '1000000' } // Send 1 KLV * }) * .data(['transfer', 'klv1receiver...', '500000']) * .build() * * // Call contract without sending value * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .smartContract({ * address: 'klv1contract...', * scType: 0 * }) * .data(['getValue']) * .build() * ``` */ smartContract(params: SmartContractRequest): this; /** * Recursively convert BigInt values to numbers for JSON serialization */ private convertBigIntToNumber; /** * Build transaction request object for node endpoint * Creates a request object that can be sent to the node's /transaction/build endpoint * The node will handle nonce fetching, fee calculation, and proto encoding * * @returns Request object ready to send to node's /transaction/build endpoint * @throws {ValidationError} If no contracts have been added * * @example * ```typescript * const builder = TransactionBuilder.create() * .sender('klv1...') * .transfer({ receiver: 'klv1...', amount: '1000000' }) * * const request = builder.buildRequest() * // Send request to node via HTTP: * // POST /transaction/build * // Body: request * ``` */ buildRequest(): BuildTransactionRequest; /** * Build proto transaction offline (client-side, no network required) * This method creates a transaction entirely on the client side without contacting the node. * You must provide all required parameters (sender, nonce, fees) either via builder state or options. * * **Offline Mode Benefits:** * - No network latency * - Works without internet connection * - Full control over transaction parameters * - Ideal for hardware wallets and air-gapped signing * * **Fee Calculation:** * When building offline, fees must be provided manually or estimated: * - KAppFee: Base fee for the contract type (typically 500000-1000000) * - BandwidthFee: Fee based on transaction size (typically 100000-500000) * - KDAFee: Optional - pay fees in custom KDA instead of KLV * * @param options - Build options (sender, nonce, fees, etc.) * @param options.sender - Sender's bech32 address (required if not set via builder) * @param options.nonce - Transaction nonce (required if not set via builder) * @param options.chainId - Chain ID (defaults to provider's network if available) * @param options.fees - Fee amounts (kAppFee and bandwidthFee) * @param options.kdaFee - Optional KDA fee (pay fees in custom asset) * @param options.permissionId - Optional permission ID for multi-sig * @param options.data - Optional transaction data * @returns Transaction object with proto bytes ready to sign * @throws {ValidationError} If required parameters are missing or invalid * * @example * ```typescript * // Offline build with all parameters in options * const tx = TransactionBuilder.create() * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .buildProto({ * sender: 'klv1xyz...', * nonce: 123, * chainId: '100', * fees: { * kAppFee: 500000, * bandwidthFee: 100000 * } * }) * * await tx.sign(privateKey) * const hex = tx.toHex() * * // Offline build using builder state * const tx = TransactionBuilder.create() * .sender('klv1xyz...') * .nonce(123) * .setChainId('100') * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .buildProto({ * fees: { kAppFee: 500000, bandwidthFee: 100000 } * }) * * // Offline build with KDA fee (pay fees in custom token) * const tx = TransactionBuilder.create() * .sender('klv1xyz...') * .nonce(123) * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .buildProto({ * chainId: '100', * fees: { kAppFee: 0, bandwidthFee: 0 }, * kdaFee: { kda: 'MYTOKEN-ABCD', amount: '1000000' } * }) * ``` */ buildProto(options?: BuildCallOptions): Transaction; /** * Build transaction using node endpoint (requires provider) * This is the recommended method for most use cases as the node handles complex operations. * * **Node-Assisted Building:** * The node automatically handles: * - Nonce fetching (gets current account nonce) * - Fee calculation (computes optimal kAppFee and bandwidthFee) * - Proto encoding (creates valid proto bytes) * - Validation (ensures transaction is valid) * * **When to Use:** * - Standard wallet applications * - When you have internet connectivity * - When you want automatic fee calculation * - When you don't need to control every parameter * * **Comparison with buildProto():** * - build() = Online, automatic, easy (requires provider) * - buildProto() = Offline, manual, flexible (no network needed) * * @returns Transaction object with proto bytes from node, ready to sign * @throws {ValidationError} If provider is not set or no contracts added * @throws {Error} If node response is invalid or network request fails * * @example * ```typescript * // Simple node-assisted build * const provider = new KleverProvider({ network: 'mainnet' }) * const tx = await TransactionBuilder.create(provider) * .sender('klv1xyz...') * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .build() * * // Node automatically fetches nonce and calculates fees * await tx.sign(privateKey) * const hash = await provider.sendRawTransaction(tx.toHex()) * * // Build with multiple contracts * const tx = await TransactionBuilder.create(provider) * .sender('klv1xyz...') * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .freeze({ amount: '5000000' }) * .delegate({ receiver: 'klv1validator...' }) * .build() * * // Override specific parameters * const tx = await TransactionBuilder.create(provider) * .sender('klv1xyz...') * .nonce(150) // Override automatic nonce * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .build() * ``` */ build(): Promise; /** * Reset builder state to initial values * Clears all contracts and builder configuration, allowing reuse of the builder instance * * **What gets reset:** * - All added contracts * - Sender address * - Nonce * - KDA fee * - Permission ID * - Transaction data * * **What persists:** * - Provider (if set) * - Chain ID (if set) * * @returns This builder instance for chaining * * @example * ```typescript * const builder = TransactionBuilder.create(provider) * * // Build first transaction * const tx1 = await builder * .sender('klv1...') * .transfer({ receiver: 'klv1abc...', amount: '1000000' }) * .build() * * // Reset and build second transaction * const tx2 = await builder * .reset() * .sender('klv1...') * .freeze({ amount: '5000000' }) * .build() * ``` */ reset(): this; } /** * Helper functions for creating common Klever transactions * These provide a simple, function-based API as an alternative to the builder pattern */ /** * Create a simple transfer request * Helper function to create a transfer request object for the TransactionBuilder * * @param params - Transfer parameters * @param params.receiver - Recipient's bech32 address * @param params.amount - Amount to transfer in smallest units (string, number, or bigint) * @param params.kda - Optional asset ID (defaults to KLV if not specified) * @returns TransferRequest object ready to use with builder.transfer() * * @example * ```typescript * const transfer = createTransfer({ * receiver: 'klv1abc...', * amount: '1000000', * kda: 'KLV' * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1xyz...') * .transfer(transfer) * .build() * ``` */ declare function createTransfer(params: { receiver: string; amount: AmountLike; kda?: string; }): TransferRequest; /** * Create a transfer with royalties * Used for NFT transfers that include royalty payments to creators * * @param params - Transfer parameters with royalties * @param params.receiver - Recipient's bech32 address * @param params.amount - Amount to transfer in smallest units * @param params.kda - Optional asset ID (typically an NFT) * @param params.kdaRoyalties - Optional royalties in KDA asset * @param params.klvRoyalties - Optional royalties in KLV * @returns TransferRequest object with royalties * * @example * ```typescript * const transfer = createTransferWithRoyalties({ * receiver: 'klv1abc...', * amount: '1', * kda: 'NFT-COLLECTION/NONCE-1', * kdaRoyalties: '100000', * klvRoyalties: '50000' * }) * ``` */ declare function createTransferWithRoyalties(params: { receiver: string; amount: AmountLike; kda?: string; kdaRoyalties?: AmountLike; klvRoyalties?: AmountLike; }): TransferRequest; /** * Create a freeze (stake) request * Freezing locks assets and creates a bucket that can be delegated or used for governance * * @param params - Freeze parameters * @param params.amount - Amount to freeze in smallest units * @param params.kda - Optional asset ID to freeze (defaults to KLV) * @returns FreezeRequest object ready to use with builder.freeze() * * @example * ```typescript * const freeze = createFreeze({ * amount: '5000000', * kda: 'KLV' * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1xyz...') * .freeze(freeze) * .build() * ``` */ declare function createFreeze(params: { amount: AmountLike; kda?: string; }): FreezeRequest; /** * Create an unfreeze (unstake) request * Unfreezing initiates the unlock period for frozen assets * * @param params - Unfreeze parameters * @param params.bucketId - Bucket ID to unfreeze * @param params.kda - Optional asset ID (required for KLV) * @returns UnfreezeRequest object ready to use with builder.unfreeze() * * @example * ```typescript * const unfreeze = createUnfreeze({ * bucketId: 'bucket-hash-123', * kda: 'KLV' * }) * ``` */ declare function createUnfreeze(params: { bucketId: string; kda?: string; }): UnfreezeRequest; /** * Create a delegate request * Delegates a frozen bucket to a validator for staking * * @param params - Delegate parameters * @param params.receiver - Validator's bech32 address * @param params.bucketId - Optional bucket ID to delegate * @returns DelegateRequest object ready to use with builder.delegate() * * @example * ```typescript * const delegate = createDelegate({ * receiver: 'klv1validator...', * bucketId: 'bucket123' * }) * ``` */ declare function createDelegate(params: { receiver: string; bucketId?: string; }): DelegateRequest; /** * Create an undelegate request * Removes delegation from a validator, returning bucket to your control * * @param params - Undelegate parameters * @param params.bucketId - Bucket ID to undelegate (required) * @returns UndelegateRequest object ready to use with builder.undelegate() * * @example * ```typescript * const undelegate = createUndelegate({ * bucketId: 'bucket-hash-123' * }) * ``` */ declare function createUndelegate(params: { bucketId: string; }): UndelegateRequest; /** * Create a withdraw request * Withdraws available funds (staking rewards, unlocked assets, etc.) * * @param params - Withdraw parameters * @param params.withdrawType - Type of withdrawal (0 = staking, 1 = FPR, etc.) * @param params.kda - Optional asset ID to withdraw * @param params.amount - Optional specific amount to withdraw * @param params.currencyID - Optional currency ID for cross-currency withdrawals * @returns WithdrawRequest object ready to use with builder.withdraw() * * @example * ```typescript * const withdraw = createWithdraw({ * withdrawType: 0, // Staking rewards * kda: 'KLV' * }) * ``` */ declare function createWithdraw(params: { withdrawType: number; kda?: string; amount?: AmountLike; currencyID?: string; }): WithdrawRequest; /** * Create a claim request * Claims rewards or allocations (staking rewards, airdrops, etc.) * * @param params - Claim parameters * @param params.claimType - Type of claim (0 = staking rewards, 1 = market rewards, etc.) * @param params.id - Optional claim ID for specific claims * @returns ClaimRequest object ready to use with builder.claim() * * @example * ```typescript * const claim = createClaim({ * claimType: 0, // Staking rewards * id: 'claim123' * }) * ``` */ declare function createClaim(params: { claimType: number; id?: string; }): ClaimRequest; /** * Create a basic fungible token (FT) * Fungible tokens are divisible assets like coins or tokens * * @param params - Fungible token parameters * @param params.name - Full name of the token * @param params.ticker - Short ticker symbol (e.g., "MTK") * @param params.ownerAddress - Owner's bech32 address * @param params.precision - Number of decimal places (e.g., 6 for standard tokens) * @param params.maxSupply - Maximum supply in smallest units * @param params.initialSupply - Optional initial supply to mint * @param params.properties - Optional token properties (mintable, burnable, etc.) * @returns CreateAssetRequest object ready to use with builder.createAsset() * * @example * ```typescript * const asset = createFungibleToken({ * name: 'My Token', * ticker: 'MTK', * ownerAddress: 'klv1...', * precision: 6, * maxSupply: '1000000000000', * initialSupply: '100000000000' * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .createAsset(asset) * .build() * ``` */ declare function createFungibleToken(params: { name: string; ticker: string; ownerAddress: string; precision: number; maxSupply: AmountLike; initialSupply?: AmountLike; properties?: CreateAssetRequest['properties']; }): CreateAssetRequest; /** * Create an NFT collection * NFTs are non-fungible tokens with unique properties and metadata * * @param params - NFT collection parameters * @param params.name - Collection name * @param params.ticker - Collection ticker symbol * @param params.ownerAddress - Owner's bech32 address * @param params.logo - Optional logo URI * @param params.uris - Optional metadata URIs * @param params.properties - Optional collection properties * @param params.royalties - Optional royalty configuration * @returns CreateAssetRequest object ready to use with builder.createAsset() * * @example * ```typescript * const nftCollection = createNFTCollection({ * name: 'My NFT Collection', * ticker: 'MYNFT', * ownerAddress: 'klv1...', * logo: 'ipfs://...', * royalties: { * address: 'klv1...', * percentage: 5 // 5% royalties * } * }) * ``` */ declare function createNFTCollection(params: { name: string; ticker: string; ownerAddress: string; logo?: string; uris?: Record; properties?: CreateAssetRequest['properties']; royalties?: CreateAssetRequest['royalties']; }): CreateAssetRequest; /** * Mint NFT * Creates a new NFT within an existing collection * * @param params - Mint NFT parameters * @param params.assetId - NFT collection asset ID * @param params.receiver - Optional recipient address (defaults to sender) * @param params.uris - Optional metadata URIs for the NFT * @param params.mime - Optional MIME type for the NFT * @returns AssetTriggerRequest object for minting NFT * * @example * ```typescript * const mintNFT = createMintNFT({ * assetId: 'MYNFT-ABCD', * receiver: 'klv1...', * uris: { * image: 'ipfs://...', * metadata: 'ipfs://...' * }, * mime: 'image/png' * }) * ``` */ declare function createMintNFT(params: { assetId: string; receiver?: string; uris?: Record; mime?: string; }): AssetTriggerRequest; /** * Burn asset * Permanently destroys tokens, reducing total supply * * @param params - Burn parameters * @param params.assetId - Asset ID to burn * @param params.amount - Amount to burn in smallest units * @returns AssetTriggerRequest object for burning tokens * * @example * ```typescript * const burn = createBurn({ * assetId: 'MYTOKEN-ABCD', * amount: '1000000' * }) * ``` */ declare function createBurn(params: { assetId: string; amount: AmountLike; }): AssetTriggerRequest; /** * Wipe asset (admin only) * Removes tokens from a specific address (admin function) * * @param params - Wipe parameters * @param params.assetId - Asset ID to wipe * @param params.receiver - Address to wipe tokens from * @param params.amount - Amount to wipe in smallest units * @returns AssetTriggerRequest object for wiping tokens * * @example * ```typescript * const wipe = createWipe({ * assetId: 'MYTOKEN-ABCD', * receiver: 'klv1...', * amount: '1000000' * }) * ``` */ declare function createWipe(params: { assetId: string; receiver: string; amount: AmountLike; }): AssetTriggerRequest; /** * Pause asset (admin only) * Temporarily freezes all transfers of the asset * * @param params - Pause parameters * @param params.assetId - Asset ID to pause * @returns AssetTriggerRequest object for pausing asset * * @example * ```typescript * const pause = createPause({ * assetId: 'MYTOKEN-ABCD' * }) * ``` */ declare function createPause(params: { assetId: string; }): AssetTriggerRequest; /** * Resume asset (admin only) * Resumes transfers of a paused asset * * @param params - Resume parameters * @param params.assetId - Asset ID to resume * @returns AssetTriggerRequest object for resuming asset * * @example * ```typescript * const resume = createResume({ * assetId: 'MYTOKEN-ABCD' * }) * ``` */ declare function createResume(params: { assetId: string; }): AssetTriggerRequest; /** * Create a validator node registration * Registers a new validator to participate in network consensus * * **Requirements:** * - Valid BLS public key for consensus signing * - Sufficient minimum stake amount * - Unique validator configuration * * @param params - Validator parameters * @param params.blsPublicKey - BLS public key for validator signing (hex format) * @param params.ownerAddress - Owner's bech32 address * @param params.commission - Commission rate percentage (0-100, e.g., 10 = 10%) * @param params.canDelegate - Optional: Whether delegators can stake (defaults to true) * @param params.rewardAddress - Optional: Separate address to receive rewards * @param params.maxDelegationAmount - Optional: Maximum delegation limit * @param params.name - Optional: Validator display name * @param params.logo - Optional: Logo URL or URI * @param params.uris - Optional: Additional URIs (website, social media, etc.) * @returns CreateValidatorRequest object ready to use with builder.createValidator() * * @example * ```typescript * // Create validator with full details * const validator = createValidator({ * blsPublicKey: '0xabcd1234...', * ownerAddress: 'klv1...', * commission: 10, // 10% commission * canDelegate: true, * name: 'My Validator', * logo: 'https://example.com/logo.png', * uris: { * website: 'https://validator.example.com', * twitter: 'https://twitter.com/myvalidator' * } * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .createValidator(validator) * .build() * ``` */ declare function createValidator(params: { blsPublicKey: string; ownerAddress: string; commission: number; canDelegate?: boolean; rewardAddress?: string; maxDelegationAmount?: AmountLike; name?: string; logo?: string; uris?: Record; }): CreateValidatorRequest; /** * Create a governance proposal for network parameter changes * Proposals allow the community to vote on changes to network configuration * * @param params - Proposal parameters * @param params.parameters - Map of parameter IDs to new values * @param params.description - Optional human-readable description of the proposal * @param params.epochsDuration - Optional duration in epochs for voting period * @returns ProposalRequest object ready to use with builder * * @example * ```typescript * // Create proposal to change network parameters * const proposal = createProposal({ * parameters: { * 1: '1000000', // Parameter 1: New value * 5: '500000' // Parameter 5: New value * }, * description: 'Increase minimum stake amount', * epochsDuration: 10 // 10 epochs for voting * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .addContract({ contractType: 13, ...proposal }) * .build() * ``` */ declare function createProposal(params: { parameters: Record; description?: string; epochsDuration?: number; }): ProposalRequest; /** * Vote on a governance proposal * Allows token holders to vote on active proposals * * **Vote Types:** * - 0: Abstain (don't vote) * - 1: Yes (approve proposal) * - 2: No (reject proposal) * * @param params - Vote parameters * @param params.proposalId - ID of the proposal to vote on * @param params.type - Vote type (0 = abstain, 1 = yes, 2 = no) * @param params.amount - Optional stake amount to weight the vote * @returns VoteRequest object ready to use with builder.vote() * * @example * ```typescript * // Vote yes on proposal * const vote = createVote({ * proposalId: 5, * type: 1, // Yes * amount: '1000000' // Optional voting weight * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .vote(vote) * .build() * ``` */ declare function createVote(params: { proposalId: number; type: number; amount?: AmountLike; }): VoteRequest; /** * Set account name to create a human-readable identifier * Account names provide an easy-to-remember alias for addresses * * @param params - Account name parameters * @param params.name - Desired account name (must be unique on the network) * @returns SetAccountNameRequest object ready to use with builder * * @example * ```typescript * // Set a readable account name * const setName = createSetAccountName({ * name: 'myaccount' * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .addContract({ contractType: 15, ...setName }) * .build() * * // After setting, users can send to "myaccount" instead of "klv1..." * ``` */ declare function createSetAccountName(params: { name: string; }): SetAccountNameRequest; /** * Create a smart contract call * Interacts with deployed smart contracts on the Klever blockchain * * @param params - Smart contract call parameters * @param params.address - Optional contract bech32 address * @param params.scType - Contract call type (0 = invoke, 1 = deploy, 2 = upgrade) * @param params.callValue - Optional KLV or KDA amounts to send with the call * @returns SmartContractRequest object ready to use with builder.smartContract() * * @example * ```typescript * const scCall = createSmartContractCall({ * address: 'klv1contract...', * scType: 0, // Invoke * callValue: { * 'KLV': '1000000' * } * }) * * const tx = await TransactionBuilder.create(provider) * .sender('klv1...') * .smartContract(scCall) * .data(['functionName', 'arg1', 'arg2']) * .build() * ``` */ declare function createSmartContractCall(params: SmartContractRequest): SmartContractRequest; /** * Convert KLV to the smallest unit (6 decimals) * KLV uses 6 decimal places, so 1 KLV = 1,000,000 smallest units * * @param amount - Amount in KLV (e.g., "1.5" or 1.5) * @returns Amount in smallest units as string (e.g., "1500000") * * @example * ```typescript * const amount = toKLVUnits('1.5') // Returns '1500000' * const amount2 = toKLVUnits(10) // Returns '10000000' * const amount3 = toKLVUnits('0.000001') // Returns '1' * ``` */ declare function toKLVUnits(amount: string | number): string; /** * Convert smallest units to KLV * Converts from 6-decimal smallest units back to human-readable KLV * * @param amount - Amount in smallest units (string, number, or bigint) * @returns Amount in KLV as string (e.g., "1.5") * * @example * ```typescript * const klv = fromKLVUnits('1500000') // Returns '1.5' * const klv2 = fromKLVUnits(10000000) // Returns '10' * const klv3 = fromKLVUnits(1n) // Returns '0.000001' * ``` */ declare function fromKLVUnits(amount: string | number | bigint): string; /** * Convert amount with custom precision * Useful for custom KDA tokens with different decimal places * * @param amount - Amount in human-readable format * @param precision - Number of decimal places (e.g., 6 for KLV, 8 for some tokens) * @returns Amount in smallest units as string * * @example * ```typescript * // Convert token with 8 decimals * const amount = toUnits('1.5', 8) // Returns '150000000' * * // Convert token with 2 decimals * const amount2 = toUnits('100.50', 2) // Returns '10050' * ``` */ declare function toUnits(amount: string | number, precision: number): string; /** * Convert from units with custom precision * Converts smallest units back to human-readable format for custom tokens * * @param amount - Amount in smallest units * @param precision - Number of decimal places * @returns Amount in human-readable format as string * * @example * ```typescript * // Convert token with 8 decimals * const readable = fromUnits('150000000', 8) // Returns '1.5' * * // Convert token with 2 decimals * const readable2 = fromUnits('10050', 2) // Returns '100.5' * ``` */ declare function fromUnits(amount: string | number | bigint, precision: number): string; export { type BuildCallOptions, Transaction, TransactionBuilder, createBurn, createClaim, createDelegate, createFreeze, createFungibleToken, createMintNFT, createNFTCollection, createPause, createProposal, createResume, createSetAccountName, createSmartContractCall, createTransfer, createTransferWithRoyalties, createUndelegate, createUnfreeze, createValidator, createVote, createWipe, createWithdraw, fromKLVUnits, fromUnits, toKLVUnits, toUnits };