This class provides methods to interact with the DEMOS blockchain.

Constructors

Properties

algorithm: SigningAlgorithm = "ed25519"
connected: boolean = false

Connection status of the RPC URL

crypto: UnifiedCrypto = null
DemosTransactions: {
    broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>);
    broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>);
    confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>);
    empty: (() => Transaction);
    prepare: ((data?: any) => Promise<Transaction>);
    sign: ((raw_tx: Transaction, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<Transaction>);
    signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>);
    _demNumberToOsBigint(amountDem: number): bigint;
    createL2PSHashUpdate(l2psUid: string, consolidatedHash: string, transactionCount: number, demos: Demos): Promise<Transaction>;
    pay(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    proposeNetworkUpgrade(params: {
        effectiveAtBlock: number;
        proposalId: string;
        proposedParameters: Partial<NetworkParameters>;
        rationale: string;
    }, demos: Demos): Promise<Transaction>;
    stake(amount: string, connectionUrl: string, demos: Demos): Promise<Transaction>;
    store(bytes: Uint8Array<ArrayBufferLike>, demos: Demos): Promise<Transaction>;
    transfer(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    unstake(demos: Demos): Promise<Transaction>;
    validatorExit(demos: Demos): Promise<Transaction>;
    voteOnUpgrade(proposalId: string, approve: boolean, demos: Demos): Promise<Transaction>;
} = DemosTransactions

Type declaration

  • broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>)

    Broadcasts a transaction for execution.

      • (validationData, demos): Promise<any>
      • Parameters

        Returns Promise<any>

        The response from the node

  • broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>)

    Broadcast a confirmed transaction and wait for inclusion.

    Polls the node's getTransactionStatus RPC until the tx is observed included or failed, or until opts.timeoutMs elapses (default 30s).

    Use this when you want a single call with a deterministic outcome. Use plain broadcast() when you want to handle async confirmation yourself.

    On timeout, throws BroadcastTimeoutError carrying the tx hash, the last observed state, and the elapsed time so the caller can resume polling.

    When opts.failFastOnBroadcastError is true, also throws BroadcastFailedError synchronously when the broadcast itself can't reach the node (e.g., ECONNREFUSED, ENOTFOUND). HTTP 5xx responses are NOT considered fail-fast cases - the server did answer, so the tx may still have landed and polling should run. Defaults to false for one release to preserve current callers' behavior.

      • (validationData, demos, opts?): Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>
      • Parameters

        • validationData: RPCResponseWithValidityData

          The validity data of the transaction (from confirm)

        • demos: Demos

          The demos instance

        • Optionalopts: {
              failFastOnBroadcastError?: boolean;
              pollIntervalMs?: number;
              timeoutMs?: number;
          }
          • OptionalfailFastOnBroadcastError?: boolean

            If true, throw BroadcastFailedError immediately when the broadcast can't contact the node. Defaults to false.

          • OptionalpollIntervalMs?: number

            Delay between status polls. Defaults to 500.

          • OptionaltimeoutMs?: number

            Total time to wait for inclusion. Defaults to 30_000.

        Returns Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>

        The original broadcast response and the terminal status.

  • confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>)

    Confirms a transaction.

  • empty: (() => Transaction)
  • prepare: ((data?: any) => Promise<Transaction>)
  • sign: ((raw_tx: Transaction, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<Transaction>)

    Signs a transaction after hashing its content.

    Use demos.sign(tx) instead

  • signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>)

    Signs a message with a given algorithm.

      • (data, keypair, options): Promise<{
            data: string;
            type: SigningAlgorithm;
        }>
      • Parameters

        • data: string

          The message to sign.

        • keypair: IKeyPair

          The keypair to use for signing.

        • options: {
              algorithm: SigningAlgorithm;
          }

        Returns Promise<{
            data: string;
            type: SigningAlgorithm;
        }>

        A Promise that resolves to the signed message.

  • _demNumberToOsBigint:function
    • Convert a legacy DEM number input to an OS bigint for internal carrying. Only whole-DEM number inputs are accepted on this legacy path — fractional DEM is rejected with a clear error directing callers to the bigint OS path (denomination.demToOs).

      Rationale: silently flooring (the previous behaviour) discarded up to ~10^9 OS per call without warning. The migration period tolerates legacy number callers, but only at exact DEM granularity — anything sub-DEM must come in as bigint so the caller has explicitly opted into OS arithmetic.

      Parameters

      • amountDem: number

      Returns bigint

  • createL2PSHashUpdate:function
    • Create a signed L2PS hash update transaction for DTR relay to validators.

      L2PS hash updates are self-directed transactions that carry consolidated hash information representing multiple L2PS transactions. These transactions are automatically relayed to validators via DTR (Distributed Transaction Routing) to enable consensus on L2PS network activity without exposing transaction content.

      Parameters

      • l2psUid: string

        The unique identifier of the L2PS network

      • consolidatedHash: string

        SHA-256 hash representing all L2PS transactions

      • transactionCount: number

        Number of transactions included in this hash update

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed L2PS hash update transaction

      const hashUpdateTx = await DemosTransactions.createL2PSHashUpdate(
      "l2ps_network_123",
      "0x1234567890abcdef...",
      5,
      demos
      )
  • pay:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      P4 dual-input:

      • bigint: OS amount (preferred — 1 DEM = 10^9 OS).
      • number: DEM amount (legacy, deprecated). Auto-converted to OS.

      Internal carrier in tx.content.amount is bigint OS; the serializerGate (run from demos.sign) emits the right wire shape per the connected node's fork status.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • proposeNetworkUpgrade:function
    • Create a signed networkUpgrade proposal transaction.

      Only active validators may propose. The node rejects proposals whose proposedParameters violate safety bounds (≤50% change, absolute floor/ceiling) or overlap keys with other pending/activating proposals.

      Parameters

      • params: {
            effectiveAtBlock: number;
            proposalId: string;
            proposedParameters: Partial<NetworkParameters>;
            rationale: string;
        }
        • effectiveAtBlock: number

          Activation block. Must be ≥ tallyBlock + grace period.

        • proposalId: string

          UUID. Also used as lexicographic activation-order tiebreaker.

        • proposedParameters: Partial<NetworkParameters>

          Subset of NetworkParameters to change.

        • rationale: string

          Human-readable reason, ≤1024 bytes.

      • demos: Demos

      Returns Promise<Transaction>

  • stake:function
    • Create a signed validatorStake transaction. Used both for initial validator registration and to top up an existing stake.

      Parameters

      • amount: string

        Stake amount in base-unit DEMOS, encoded as a bigint string.

      • connectionUrl: string

        Validator's public endpoint (required on first stake; subsequent top-ups may overwrite it).

      • demos: Demos

        The demos instance (for nonce + signing).

      Returns Promise<Transaction>

  • store:function
    • Create a signed DEMOS transaction to store binary data on the blockchain. Data is stored in the sender's account.

      Parameters

      • bytes: Uint8Array<ArrayBufferLike>

        The binary data to store (will be base64-encoded)

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed storage transaction.

  • transfer:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      Alias of pay. Same dual-input semantics — bigint OS preferred, number DEM accepted as the deprecated path.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • unstake:function
  • validatorExit:function
  • voteOnUpgrade:function
    • Create a signed networkUpgradeVote transaction.

      The voter must be in the validator snapshot taken at the proposal's confirmation block, and may cast exactly one vote per proposal (final, non-revocable).

      Parameters

      • proposalId: string
      • approve: boolean
      • demos: Demos

      Returns Promise<Transaction>

DemosWebAuth: typeof DemosWebAuth = DemosWebAuth
dual_sign: boolean = false
ipfs: {
    quote: ((fileSizeBytes: number, operation?: "IPFS_ADD" | "IPFS_PIN" | "IPFS_UNPIN", durationBlocks?: number) => Promise<{
        breakdown: {
            base_cost: string;
            chargeable_bytes: number;
            free_tier_bytes: number;
            size_cost: string;
        };
        cost_dem?: string;
        cost_os?: string;
        file_size_bytes: number;
        is_genesis: boolean;
        operation: string;
    }>);
} = ...

Type declaration

  • quote: ((fileSizeBytes: number, operation?: "IPFS_ADD" | "IPFS_PIN" | "IPFS_UNPIN", durationBlocks?: number) => Promise<{
        breakdown: {
            base_cost: string;
            chargeable_bytes: number;
            free_tier_bytes: number;
            size_cost: string;
        };
        cost_dem?: string;
        cost_os?: string;
        file_size_bytes: number;
        is_genesis: boolean;
        operation: string;
    }>)

    Get a cost quote for an IPFS operation without submitting a transaction.

    Use this to estimate costs and populate custom_charges before signing. Pipe the response through IPFSOperations.quoteToCustomCharges (or createCustomCharges) to obtain a max_cost_os decimal-string suitable for the transaction's custom_charges.ipfs.max_cost_os field. The helpers handle both pre-fork (cost_dem) and post-fork (cost_os) node response shapes.

    // Get quote for add operation
    const quote = await demos.ipfs.quote(content.length, 'IPFS_ADD')

    // Use quote to build transaction with cost control
    const payload = IPFSOperations.createAddPayload(content, {
    customCharges: IPFSOperations.quoteToCustomCharges(quote)
    })
      • (fileSizeBytes, operation?, durationBlocks?): Promise<{
            breakdown: {
                base_cost: string;
                chargeable_bytes: number;
                free_tier_bytes: number;
                size_cost: string;
            };
            cost_dem?: string;
            cost_os?: string;
            file_size_bytes: number;
            is_genesis: boolean;
            operation: string;
        }>
      • Parameters

        • fileSizeBytes: number

          Size of file in bytes

        • operation: "IPFS_ADD" | "IPFS_PIN" | "IPFS_UNPIN" = "IPFS_ADD"

          IPFS operation type ('IPFS_ADD', 'IPFS_PIN', or 'IPFS_UNPIN')

        • OptionaldurationBlocks: number

          Optional duration in blocks (for PIN operations)

        Returns Promise<{
            breakdown: {
                base_cost: string;
                chargeable_bytes: number;
                free_tier_bytes: number;
                size_cost: string;
            };
            cost_dem?: string;
            cost_os?: string;
            file_size_bytes: number;
            is_genesis: boolean;
            operation: string;
        }>

        Cost quote with detailed breakdown

skeletons: skeletons = skeletons
storagePrograms: {
    read: ((address: string) => Promise<StorageProgramResponse>);
    sign: ((payload: StorageProgramPayload) => Promise<Transaction>);
} = ...

Type declaration

  • read: ((address: string) => Promise<StorageProgramResponse>)

    Reads a storage program by address.

      • (address): Promise<StorageProgramResponse>
      • Parameters

        • address: string

          The address of the storage program to read

        Returns Promise<StorageProgramResponse>

        The response from the node

  • sign: ((payload: StorageProgramPayload) => Promise<Transaction>)

    Creates and signs a storage program transaction given a payload.

transactions: {
    broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>);
    broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>);
    confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>);
    empty: (() => Transaction);
    prepare: ((data?: any) => Promise<Transaction>);
    sign: ((raw_tx: Transaction, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<Transaction>);
    signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>);
    _demNumberToOsBigint(amountDem: number): bigint;
    createL2PSHashUpdate(l2psUid: string, consolidatedHash: string, transactionCount: number, demos: Demos): Promise<Transaction>;
    pay(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    proposeNetworkUpgrade(params: {
        effectiveAtBlock: number;
        proposalId: string;
        proposedParameters: Partial<NetworkParameters>;
        rationale: string;
    }, demos: Demos): Promise<Transaction>;
    stake(amount: string, connectionUrl: string, demos: Demos): Promise<Transaction>;
    store(bytes: Uint8Array<ArrayBufferLike>, demos: Demos): Promise<Transaction>;
    transfer(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    unstake(demos: Demos): Promise<Transaction>;
    validatorExit(demos: Demos): Promise<Transaction>;
    voteOnUpgrade(proposalId: string, approve: boolean, demos: Demos): Promise<Transaction>;
} = DemosTransactions

Type declaration

  • broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>)

    Broadcasts a transaction for execution.

      • (validationData, demos): Promise<any>
      • Parameters

        Returns Promise<any>

        The response from the node

  • broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>)

    Broadcast a confirmed transaction and wait for inclusion.

    Polls the node's getTransactionStatus RPC until the tx is observed included or failed, or until opts.timeoutMs elapses (default 30s).

    Use this when you want a single call with a deterministic outcome. Use plain broadcast() when you want to handle async confirmation yourself.

    On timeout, throws BroadcastTimeoutError carrying the tx hash, the last observed state, and the elapsed time so the caller can resume polling.

    When opts.failFastOnBroadcastError is true, also throws BroadcastFailedError synchronously when the broadcast itself can't reach the node (e.g., ECONNREFUSED, ENOTFOUND). HTTP 5xx responses are NOT considered fail-fast cases - the server did answer, so the tx may still have landed and polling should run. Defaults to false for one release to preserve current callers' behavior.

      • (validationData, demos, opts?): Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>
      • Parameters

        • validationData: RPCResponseWithValidityData

          The validity data of the transaction (from confirm)

        • demos: Demos

          The demos instance

        • Optionalopts: {
              failFastOnBroadcastError?: boolean;
              pollIntervalMs?: number;
              timeoutMs?: number;
          }
          • OptionalfailFastOnBroadcastError?: boolean

            If true, throw BroadcastFailedError immediately when the broadcast can't contact the node. Defaults to false.

          • OptionalpollIntervalMs?: number

            Delay between status polls. Defaults to 500.

          • OptionaltimeoutMs?: number

            Total time to wait for inclusion. Defaults to 30_000.

        Returns Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>

        The original broadcast response and the terminal status.

  • confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>)

    Confirms a transaction.

  • empty: (() => Transaction)
  • prepare: ((data?: any) => Promise<Transaction>)
  • sign: ((raw_tx: Transaction, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<Transaction>)

    Signs a transaction after hashing its content.

    Use demos.sign(tx) instead

  • signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>)

    Signs a message with a given algorithm.

      • (data, keypair, options): Promise<{
            data: string;
            type: SigningAlgorithm;
        }>
      • Parameters

        • data: string

          The message to sign.

        • keypair: IKeyPair

          The keypair to use for signing.

        • options: {
              algorithm: SigningAlgorithm;
          }

        Returns Promise<{
            data: string;
            type: SigningAlgorithm;
        }>

        A Promise that resolves to the signed message.

  • _demNumberToOsBigint:function
    • Convert a legacy DEM number input to an OS bigint for internal carrying. Only whole-DEM number inputs are accepted on this legacy path — fractional DEM is rejected with a clear error directing callers to the bigint OS path (denomination.demToOs).

      Rationale: silently flooring (the previous behaviour) discarded up to ~10^9 OS per call without warning. The migration period tolerates legacy number callers, but only at exact DEM granularity — anything sub-DEM must come in as bigint so the caller has explicitly opted into OS arithmetic.

      Parameters

      • amountDem: number

      Returns bigint

  • createL2PSHashUpdate:function
    • Create a signed L2PS hash update transaction for DTR relay to validators.

      L2PS hash updates are self-directed transactions that carry consolidated hash information representing multiple L2PS transactions. These transactions are automatically relayed to validators via DTR (Distributed Transaction Routing) to enable consensus on L2PS network activity without exposing transaction content.

      Parameters

      • l2psUid: string

        The unique identifier of the L2PS network

      • consolidatedHash: string

        SHA-256 hash representing all L2PS transactions

      • transactionCount: number

        Number of transactions included in this hash update

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed L2PS hash update transaction

      const hashUpdateTx = await DemosTransactions.createL2PSHashUpdate(
      "l2ps_network_123",
      "0x1234567890abcdef...",
      5,
      demos
      )
  • pay:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      P4 dual-input:

      • bigint: OS amount (preferred — 1 DEM = 10^9 OS).
      • number: DEM amount (legacy, deprecated). Auto-converted to OS.

      Internal carrier in tx.content.amount is bigint OS; the serializerGate (run from demos.sign) emits the right wire shape per the connected node's fork status.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • proposeNetworkUpgrade:function
    • Create a signed networkUpgrade proposal transaction.

      Only active validators may propose. The node rejects proposals whose proposedParameters violate safety bounds (≤50% change, absolute floor/ceiling) or overlap keys with other pending/activating proposals.

      Parameters

      • params: {
            effectiveAtBlock: number;
            proposalId: string;
            proposedParameters: Partial<NetworkParameters>;
            rationale: string;
        }
        • effectiveAtBlock: number

          Activation block. Must be ≥ tallyBlock + grace period.

        • proposalId: string

          UUID. Also used as lexicographic activation-order tiebreaker.

        • proposedParameters: Partial<NetworkParameters>

          Subset of NetworkParameters to change.

        • rationale: string

          Human-readable reason, ≤1024 bytes.

      • demos: Demos

      Returns Promise<Transaction>

  • stake:function
    • Create a signed validatorStake transaction. Used both for initial validator registration and to top up an existing stake.

      Parameters

      • amount: string

        Stake amount in base-unit DEMOS, encoded as a bigint string.

      • connectionUrl: string

        Validator's public endpoint (required on first stake; subsequent top-ups may overwrite it).

      • demos: Demos

        The demos instance (for nonce + signing).

      Returns Promise<Transaction>

  • store:function
    • Create a signed DEMOS transaction to store binary data on the blockchain. Data is stored in the sender's account.

      Parameters

      • bytes: Uint8Array<ArrayBufferLike>

        The binary data to store (will be base64-encoded)

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed storage transaction.

  • transfer:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      Alias of pay. Same dual-input semantics — bigint OS preferred, number DEM accepted as the deprecated path.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • unstake:function
  • validatorExit:function
  • voteOnUpgrade:function
    • Create a signed networkUpgradeVote transaction.

      The voter must be in the validator snapshot taken at the proposal's confirmation block, and may cast exactly one vote per proposal (final, non-revocable).

      Parameters

      • proposalId: string
      • approve: boolean
      • demos: Demos

      Returns Promise<Transaction>

tx: {
    broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>);
    broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>);
    confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>);
    empty: (() => Transaction);
    prepare: ((data?: any) => Promise<Transaction>);
    sign: ((raw_tx: Transaction) => Promise<Transaction>);
    signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>);
    _demNumberToOsBigint(amountDem: number): bigint;
    createL2PSHashUpdate(l2psUid: string, consolidatedHash: string, transactionCount: number, demos: Demos): Promise<Transaction>;
    pay(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    proposeNetworkUpgrade(params: {
        effectiveAtBlock: number;
        proposalId: string;
        proposedParameters: Partial<NetworkParameters>;
        rationale: string;
    }, demos: Demos): Promise<Transaction>;
    stake(amount: string, connectionUrl: string, demos: Demos): Promise<Transaction>;
    store(bytes: Uint8Array<ArrayBufferLike>, demos: Demos): Promise<Transaction>;
    transfer(to: string, amount: number | bigint, demos: Demos): Promise<Transaction>;
    unstake(demos: Demos): Promise<Transaction>;
    validatorExit(demos: Demos): Promise<Transaction>;
    voteOnUpgrade(proposalId: string, approve: boolean, demos: Demos): Promise<Transaction>;
} = ...

Type declaration

  • broadcast: ((validationData: RPCResponseWithValidityData, demos: Demos) => Promise<any>)

    Broadcasts a transaction for execution.

      • (validationData, demos): Promise<any>
      • Parameters

        Returns Promise<any>

        The response from the node

  • broadcastAndWait: ((validationData: RPCResponseWithValidityData, demos: Demos, opts?: {
        failFastOnBroadcastError?: boolean;
        pollIntervalMs?: number;
        timeoutMs?: number;
    }) => Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>)

    Broadcast a confirmed transaction and wait for inclusion.

    Polls the node's getTransactionStatus RPC until the tx is observed included or failed, or until opts.timeoutMs elapses (default 30s).

    Use this when you want a single call with a deterministic outcome. Use plain broadcast() when you want to handle async confirmation yourself.

    On timeout, throws BroadcastTimeoutError carrying the tx hash, the last observed state, and the elapsed time so the caller can resume polling.

    When opts.failFastOnBroadcastError is true, also throws BroadcastFailedError synchronously when the broadcast itself can't reach the node (e.g., ECONNREFUSED, ENOTFOUND). HTTP 5xx responses are NOT considered fail-fast cases - the server did answer, so the tx may still have landed and polling should run. Defaults to false for one release to preserve current callers' behavior.

      • (validationData, demos, opts?): Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>
      • Parameters

        • validationData: RPCResponseWithValidityData

          The validity data of the transaction (from confirm)

        • demos: Demos

          The demos instance

        • Optionalopts: {
              failFastOnBroadcastError?: boolean;
              pollIntervalMs?: number;
              timeoutMs?: number;
          }
          • OptionalfailFastOnBroadcastError?: boolean

            If true, throw BroadcastFailedError immediately when the broadcast can't contact the node. Defaults to false.

          • OptionalpollIntervalMs?: number

            Delay between status polls. Defaults to 500.

          • OptionaltimeoutMs?: number

            Total time to wait for inclusion. Defaults to 30_000.

        Returns Promise<{
            broadcast: RPCResponse;
            status: {
                blockNumber?: number;
                state: "included" | "failed";
            };
        }>

        The original broadcast response and the terminal status.

  • confirm: ((transaction: Transaction, demos: Demos) => Promise<RPCResponseWithValidityData>)

    Confirms a transaction.

  • empty: (() => Transaction)
  • prepare: ((data?: any) => Promise<Transaction>)
  • sign: ((raw_tx: Transaction) => Promise<Transaction>)

    Same as demos.sign. Signs a transaction after hashing its content.

  • signWithAlgorithm: ((data: string, keypair: IKeyPair, options: {
        algorithm: SigningAlgorithm;
    }) => Promise<{
        data: string;
        type: SigningAlgorithm;
    }>)

    Signs a message with a given algorithm.

      • (data, keypair, options): Promise<{
            data: string;
            type: SigningAlgorithm;
        }>
      • Parameters

        • data: string

          The message to sign.

        • keypair: IKeyPair

          The keypair to use for signing.

        • options: {
              algorithm: SigningAlgorithm;
          }

        Returns Promise<{
            data: string;
            type: SigningAlgorithm;
        }>

        A Promise that resolves to the signed message.

  • _demNumberToOsBigint:function
    • Convert a legacy DEM number input to an OS bigint for internal carrying. Only whole-DEM number inputs are accepted on this legacy path — fractional DEM is rejected with a clear error directing callers to the bigint OS path (denomination.demToOs).

      Rationale: silently flooring (the previous behaviour) discarded up to ~10^9 OS per call without warning. The migration period tolerates legacy number callers, but only at exact DEM granularity — anything sub-DEM must come in as bigint so the caller has explicitly opted into OS arithmetic.

      Parameters

      • amountDem: number

      Returns bigint

  • createL2PSHashUpdate:function
    • Create a signed L2PS hash update transaction for DTR relay to validators.

      L2PS hash updates are self-directed transactions that carry consolidated hash information representing multiple L2PS transactions. These transactions are automatically relayed to validators via DTR (Distributed Transaction Routing) to enable consensus on L2PS network activity without exposing transaction content.

      Parameters

      • l2psUid: string

        The unique identifier of the L2PS network

      • consolidatedHash: string

        SHA-256 hash representing all L2PS transactions

      • transactionCount: number

        Number of transactions included in this hash update

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed L2PS hash update transaction

      const hashUpdateTx = await DemosTransactions.createL2PSHashUpdate(
      "l2ps_network_123",
      "0x1234567890abcdef...",
      5,
      demos
      )
  • pay:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      P4 dual-input:

      • bigint: OS amount (preferred — 1 DEM = 10^9 OS).
      • number: DEM amount (legacy, deprecated). Auto-converted to OS.

      Internal carrier in tx.content.amount is bigint OS; the serializerGate (run from demos.sign) emits the right wire shape per the connected node's fork status.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • proposeNetworkUpgrade:function
    • Create a signed networkUpgrade proposal transaction.

      Only active validators may propose. The node rejects proposals whose proposedParameters violate safety bounds (≤50% change, absolute floor/ceiling) or overlap keys with other pending/activating proposals.

      Parameters

      • params: {
            effectiveAtBlock: number;
            proposalId: string;
            proposedParameters: Partial<NetworkParameters>;
            rationale: string;
        }
        • effectiveAtBlock: number

          Activation block. Must be ≥ tallyBlock + grace period.

        • proposalId: string

          UUID. Also used as lexicographic activation-order tiebreaker.

        • proposedParameters: Partial<NetworkParameters>

          Subset of NetworkParameters to change.

        • rationale: string

          Human-readable reason, ≤1024 bytes.

      • demos: Demos

      Returns Promise<Transaction>

  • stake:function
    • Create a signed validatorStake transaction. Used both for initial validator registration and to top up an existing stake.

      Parameters

      • amount: string

        Stake amount in base-unit DEMOS, encoded as a bigint string.

      • connectionUrl: string

        Validator's public endpoint (required on first stake; subsequent top-ups may overwrite it).

      • demos: Demos

        The demos instance (for nonce + signing).

      Returns Promise<Transaction>

  • store:function
    • Create a signed DEMOS transaction to store binary data on the blockchain. Data is stored in the sender's account.

      Parameters

      • bytes: Uint8Array<ArrayBufferLike>

        The binary data to store (will be base64-encoded)

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed storage transaction.

  • transfer:function
    • Create a signed DEMOS transaction to send native tokens to a given address.

      Alias of pay. Same dual-input semantics — bigint OS preferred, number DEM accepted as the deprecated path.

      Parameters

      • to: string

        The reciever

      • amount: number | bigint

        DEM number (legacy) or OS bigint.

      • demos: Demos

        The demos instance (for getting the address nonce)

      Returns Promise<Transaction>

      The signed transaction.

  • unstake:function
  • validatorExit:function
  • voteOnUpgrade:function
    • Create a signed networkUpgradeVote transaction.

      The voter must be in the validator snapshot taken at the proposal's confirmation block, and may cast exactly one vote per proposal (final, non-revocable).

      Parameters

      • proposalId: string
      • approve: boolean
      • demos: Demos

      Returns Promise<Transaction>

web2: {
    createDahr: (() => Promise<Web2Proxy>);
    getDiscordMessage: ((discordUrl: string) => Promise<{
        error?: string;
        message: GetDiscordMessageResult;
        success: boolean;
    }>);
    getTweet: ((tweetUrl: string) => Promise<{
        error?: string;
        success: boolean;
        tweet: TweetSimplified;
    }>);
} = ...
xm: {
    createPayload: ((xm_payload: XMScript, keypair?: IKeyPair) => Promise<Transaction>);
} = ...

Accessors

  • get keypair(): {
        privateKey: NativeBuffer;
        publicKey: NativeBuffer;
    }
  • The keypair of the connected wallet

    Returns {
        privateKey: NativeBuffer;
        publicKey: NativeBuffer;
    }

    • privateKey: NativeBuffer
    • publicKey: NativeBuffer

Methods

  • Returns void

    Reset the cached fork status. Intended for tests; production code should construct a fresh Demos instance instead.

  • Broadcast a confirmed transaction and wait until it lands on chain (or fails) by polling the node's getTransactionStatus RPC.

    Throws BroadcastTimeoutError if no terminal state is observed before the timeout elapses. Use plain broadcast() if you want to handle async confirmation yourself.

    Parameters

    • validationData: RPCResponseWithValidityData

      The validity data of the transaction

    • Optionalopts: {
          pollIntervalMs?: number;
          timeoutMs?: number;
      }
      • OptionalpollIntervalMs?: number

        Delay between polls. Defaults to 500.

      • OptionaltimeoutMs?: number

        Total time to wait. Defaults to 30_000.

    Returns Promise<{
        broadcast: RPCResponse;
        status: {
            blockNumber?: number;
            state: "included" | "failed";
        };
    }>

  • Parameters

    • method: any
    • message: any
    • data: any = {}
    • extra: any = ""
    • sender: any = null
    • receiver: any = null

    Returns Promise<any>

  • Connects to a RPC URL. Throws an error if the connection fails.

    Parameters

    • rpc_url: string

      The URL of the demos node

    Returns Promise<boolean>

    Whether the connection was successful

  • Connects to a Demos wallet using the provided master seed.

    Parameters

    • masterSeed: string | Uint8Array<ArrayBufferLike>

      The master seed of the wallet

    • Optionaloptions: {
          algorithm?: SigningAlgorithm;
          dual_sign?: boolean;
      }

      The options for the wallet connection

      • Optionalalgorithm?: SigningAlgorithm

        The algorithm to use for the wallet

      • Optionaldual_sign?: boolean

        Whether to include the ed25519 signature along with the PQC signature, when signing with unlinked PQC keypairs (i.e. PQC keypairs not linked to your ed25519 address on the network).

    Returns Promise<string>

    The public key of the wallet

  • Generates a random MUID using a CSPRNG. Math.random is unsafe in any security-sensitive path (a predictable PRNG lets an attacker pre-compute MUIDs). 26 bytes → 52 hex chars, same length range as the legacy MUID format.

    Returns string

  • Returns the public key of the connected wallet.

    Returns string

    The public key of the wallet

  • Get information about an address.

    P4: balance is bigint in OS (smallest unit, 1 DEM = 10^9 OS). Use denomination.osToDem(info.balance) for display.

    Parameters

    • address: string

      The address

    Returns Promise<AddressInfo>

    import { denomination } from "@kynesyslabs/demosdk"
    const info = await demos.getAddressInfo("0x...")
    if (info) {
    console.log("balance:", denomination.osToDem(info.balance), "DEM")
    }
  • Get address nonce.

    Parameters

    • address: string

      The address

    Returns Promise<number>

  • Returns the ed25519 address of the connected wallet.

    Returns Promise<string>

  • Fetches the connected node's per-fork activation status.

    Mirrors the node's getNetworkInfo nodeCall (libs/network/handlers/forkHandlers.ts). The response carries activation height, current chain head, and the activated boolean for every known fork.

    Caches the result on this Demos instance for the instance's lifetime (no TTL). To re-fetch after a node upgrade, construct a fresh Demos instance.

    On RPC failure (404, malformed response, network error), this method returns null and the SDK assumes pre-fork wire format. A console.warn is emitted exactly once per Demos instance recommending the operator upgrade the target node.

    Returns Promise<NetworkInfo>

    The fork-status payload, or null if the RPC failed.

  • Returns the live vote tally for a specific proposal — total snapshot weight, approve/reject breakdowns, per-validator votes, threshold, and a passed flag.

    Parameters

    • proposalId: string

    Returns Promise<ProposalVoteInfo>

  • Convenience: return a single validator's current staked amount as a bigint-encoded string. Returns "0" for non-validators.

    Parameters

    • address: string

    Returns Promise<string>

  • Get the transaction history of an address.

    Parameters

    • address: string

      The address

    • type:
          | "web2Request"
          | "crosschainOperation"
          | "subnet"
          | "native"
          | "demoswork"
          | "genesis"
          | "NODE_ONLINE"
          | "identity"
          | "instantMessaging"
          | "l2psInstantMessaging"
          | "nativeBridge"
          | "l2psEncryptedTx"
          | "storage"
          | "storageProgram"
          | "l2ps_hash_update"
          | "contractDeploy"
          | "contractCall"
          | "d402_payment"
          | "escrow"
          | "ipfs"
          | "tokenCreation"
          | "tokenExecution"
          | "validatorStake"
          | "validatorUnstake"
          | "validatorExit"
          | "networkUpgrade"
          | "networkUpgradeVote"
          | "all" = "all"

      The type of transaction. Defaults to "all".

    • options: {
          limit?: number;
          start?: number;
      } = {}
      • Optionallimit?: number
      • Optionalstart?: number

    Returns Promise<Transaction[]>

    A list of transaction ordered from the most recent to the oldest.

  • Get a validator's current record (stake, status, unstake timestamps). Returns null if the address is not (and never was) a validator.

    Parameters

    • address: string

    Returns Promise<ValidatorInfo>

  • List validators at a given block (defaults to the current head). Only returns validators whose valid_at block is <= the queried block and whose status is still active.

    Parameters

    • OptionalblockNumber: number

    Returns Promise<ValidatorInfo[]>

  • Generates a new mnemonic.

    Parameters

    • strength: 128 | 256 = 128

      The strength of the mnemonic in bits. (128 bits = 12 words, 256 bits = 24 words). Default is 128 bits.

    Returns string

    The mnemonic

  • Performs a nodeCall on the connected RPC.

    Parameters

    • message: any

      The message to send to the node

    • args: {} = {}

      The arguments to send to the node

      Returns Promise<any>

      The nodeCall response

    • Create a signed DEMOS transaction to send native tokens to a given address.

      P4 dual-input:

      • bigint (preferred, post-v3): amount in OS (smallest unit; 1 DEM = 10^9 OS). Use denomination.demToOs(...) to convert a human-readable DEM input.
      • number (deprecated, v2 callers): amount in DEM. Auto-converted to OS internally via OS_PER_DEM. Will be removed in v4.

      Sub-DEM precision is rejected with SubDemPrecisionError when the connected node is pre-fork — its legacy DEM-number wire cannot carry < 1 DEM and silent truncation is unacceptable. The caller can either round to a whole DEM or upgrade the target node.

      Parameters

      • to: string

        The receiver address (0x-prefixed hex).

      • amount: number | bigint

        DEM number (legacy) or OS bigint (preferred).

      Returns Promise<Transaction>

      The signed transaction.

      import { denomination } from "@kynesyslabs/demosdk"
      await demos.pay("0x...", denomination.demToOs(100)) // 100 DEM
      await demos.pay("0x...", 100_000_000_000n) // raw OS
      await demos.pay("0x...", 100) // legacy DEM number (deprecated)
    • Parameters

      • request: RPCRequest
      • isAuthenticated: boolean = false
      • retries: number = 0
      • sleepTime: number = 250
      • allowedErrorCodes: number[] = []

      Returns Promise<RPCResponse>

    • Signs a message.

      Parameters

      • message: string | Buffer<ArrayBufferLike>

        The message to sign

      • Optionaloptions: {
            algorithm?: SigningAlgorithm;
        }

        The options for the message signing

        • Optionalalgorithm?: SigningAlgorithm

          The algorithm to use for the message signing. Defaults to the connected wallet's algorithm.

      Returns Promise<{
          data: string;
          type: SigningAlgorithm;
      }>

      The signature of the message

    • Create a signed DEMOS transaction to store binary data on the blockchain. Data is stored in the sender's account.

      Parameters

      • bytes: Uint8Array<ArrayBufferLike>

        The binary data to store

      Returns Promise<Transaction>

      The signed storage transaction.

    • Create a TLSNotary instance for HTTPS attestation.

      This method discovers the notary endpoints from the connected node and returns an initialized TLSNotary instance.

      Parameters

      • Optionalconfig: TLSNotaryConfig

        Optional explicit configuration (overrides discovery)

      Returns Promise<TLSNotary>

      Initialized TLSNotary instance

      // Option 1: Auto-discovery from connected node (preferred)
      const demos = new Demos({ rpc: 'https://node.demos.sh' });
      await demos.connect();
      const tlsn = await demos.tlsnotary();

      // Option 2: Explicit configuration
      const tlsn = await demos.tlsnotary({
      notaryUrl: 'wss://other-node.demos.sh:7047',
      websocketProxyUrl: 'wss://other-node.demos.sh:55688',
      });

      // Attest an HTTPS request
      const result = await tlsn.attest({
      url: 'https://api.github.com/users/octocat',
      });
      console.log('Verified server:', result.verification.serverName);
    • Create a signed DEMOS transaction to send native tokens to a given address.

      Alias of pay. Same dual-input semantics — bigint is the preferred OS shape; number is the deprecated legacy DEM shape.

      Parameters

      • to: string

        The receiver address (0x-prefixed hex).

      • amount: number | bigint

        DEM number (legacy) or OS bigint (preferred).

      Returns Promise<Transaction>

      The signed transaction.

      import { denomination } from "@kynesyslabs/demosdk"
      await demos.transfer("0x...", denomination.demToOs("1.5")) // 1.5 DEM
      await demos.transfer("0x...", 1_500_000_000n) // raw OS
    • Verifies a message.

      Parameters

      • message: string | Buffer<ArrayBufferLike>

        The message to verify

      • signature: string

        The signature of the message

      • publicKey: string

        The public key of the message

      • Optionaloptions: {
            algorithm?: SigningAlgorithm;
        }

        The options for the message verification

        • Optionalalgorithm?: SigningAlgorithm

          The algorithm to use for the message verification. Defaults to the connected wallet's algorithm or ed25519 if no wallet is connected.

      Returns Promise<boolean>

      Whether the message is verified

    • Coerce a wire-format amount/fee value (legacy DEM number, post-fork OS decimal string, or in-flight bigint) to an OS bigint. Used by _calculateAndApplyGasFee and other internal arithmetic paths to stay in OS-bigint regardless of which wire shape the caller produced. Mirrors the node's toOsBigint helper in forks/serializerGate.ts.

      Parameters

      • value: string | number | bigint

      Returns bigint