Class WebSocketRpcProvider

This class is used to provide a WebSocket RPC provider. WebSocketRpcProvider

Hierarchy (view full)

Constructors

Accessors

Methods

  • Get the bitcoin balance of an address.

    Parameters

    • addressLike: BitcoinAddressLike

      The address to get the balance of

    • filterOrdinals: boolean = true

      Whether to filter ordinals or not

    Returns Promise<bigint>

    The balance of the address

    This method is used to get the balance of a bitcoin address.

    await getBalance('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq');
    
  • Get block by number or hash.

    Parameters

    • blockNumberOrHash: BlockTag

      The block number or hash

    • prefetchTxs: boolean = false

      Whether to prefetch transactions

    Returns Promise<Block>

    The requested block

    This method is used to get a block by its number or hash.

    If the block is not found

    await getBlock(123456);
    
  • Get block by hash. This is the same method as getBlock.

    Parameters

    • blockHash: string

      The block hash

    Returns Promise<Block>

    The requested block

    This method is used to get a block by its hash. Note that this method is the same as getBlock.

    If the block is not found

  • Get multiple blocks by number or hash.

    Parameters

    • blockNumbers: BlockTag[]

      The block numbers or hashes

    • prefetchTxs: boolean = false

      Whether to prefetch transactions

    Returns Promise<Block[]>

    The requested blocks

    This method is used to get multiple blocks by their numbers or hashes.

  • Get block witnesses.

    Parameters

    • height: BigNumberish = -1

      The block number or hash, use -1 for latest block

    • Optionaltrusted: boolean

      Whether to trust the witnesses or not

    • Optionallimit: number

      The maximum number of witnesses to return

    • Optionalpage: number

      The page number of the witnesses

    Returns Promise<BlockWitnesses>

    The witnesses of the block

    This method is used to get the witnesses of a block. This proves that the action executed inside a block are valid and confirmed by the network. If the minimum number of witnesses are not met, the block is considered as potentially invalid.

    await getBlockWitness(123456n);
    

    If something went wrong while fetching the witnesses

  • Get the contract code of an address.

    Parameters

    • address: BitcoinAddressLike

      The address of the contract

    • OptionalonlyBytecode: boolean = false

      Whether to return only the bytecode

    Returns Promise<Buffer | ContractData>

    The contract data or bytecode

    This method is used to get the contract code of an address.

    await getCode('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a');
    

    If something went wrong while fetching the contract code

  • Get the storage at a specific address and pointer.

    Parameters

    • address: BitcoinAddressLike

      The address to get the storage from

    • rawPointer: string | bigint

      The pointer to get the storage from as base64 or bigint

    • proofs: boolean = true

      Whether to send proofs or not

    • Optionalheight: BigNumberish

      The height to get the storage from

    Returns Promise<StoredValue>

    The storage value

    This method is used to get the storage at a specific address and pointer.

    await getStorageAt('tb1pth90usc4f528aqphpjrfkkdm4vy8hxnt5gps6aau2nva6pxeshtqqzlt3a', 'EXLK/QhEQMI5d9DrthLvozT+UcDQ7WuSPaz7g8GV3AQ=');
    

    If something went wrong while fetching the storage

  • Generate parameters needed to wrap bitcoin.

    Parameters

    Returns Promise<WrappedGeneration>

    The wrapped generation parameters

    This method is used to generate the parameters needed to wrap bitcoin.

    await requestTrustedPublicKeyForBitcoinWrapping(100000000n);
    

    If something went wrong while generating the parameters

  • Send a raw transaction.

    Parameters

    • tx: string

      The raw transaction to send as hex string

    • Optionalpsbt: boolean

      Whether the transaction is a PSBT or not

    Returns Promise<BroadcastedTransaction>

    The result of the transaction

    This method is used to send a raw transaction.

    await sendRawTransaction('02000000000101ad897689f66c98daae5fdc3606235c1ad7a17b9e0a6aaa0ea9e58ecc1198ad2a0100000000ffffffff01a154c39400000000160014482038efcc91af945f0c756d07a46401920380520247304402201c1f8718dec637ddb41b42abc44dcbf35a94c6be6a9de8c1db48c9fa6e456b7e022032a4b3286808372a7ac2c5094d6341b4d61b17663f4ccd1c1d92efa85c7dada80121020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c00000000', false);
    

    If something went wrong while sending the transaction