# Ledger

# ledger_getAccountBlocks

Return account blocks by address

  • Parameters:

    • Address: Account address
    • Hash: Hash of account block, optional. For the latest block, filling in null
    • TokenTypeId: Token type id, optional. This is used to get the transactions associated with certain token. Otherwise, filling in null
    • uint64: Number of account blocks
  • Return:

    • list<AccountBlock>: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getAccountBlockByHash

Return account block by hash

  • Parameters:

    • Hash: Hash of account block
  • Return:

    • AccountBlock: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getAccountBlockByHeight

Return account block by height

  • Parameters:

    • Address: Account address
    • uint64: Height of account block
  • Return:

    • AccountBlock: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getAccountBlocksByAddress

Return account blocks in descent order by address

  • Parameters:

    • Address: Account address
    • uint64: Page index, start with 0
    • uint64: Page size
  • Return:

    • List<AccountBlock>: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getLatestAccountBlock

Return the latest account block

  • Parameters:

    • Address: Account address
  • Return:

    • AccountBlock: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getSnapshotChainHeight

Return current snapshot chain height

  • Parameters: none

  • Return:

    • string of uint64: The current height of snapshot chain
  • Example:

# ledger_getSnapshotBlockByHash

Return snapshot block by hash

  • Parameters:

    • Hash Hash of snapshot block
  • Returns: Object : Snapshot block

    • producer : string Snapshot block producer
    • hash : Hash Hash of snapshot block
    • previousHash : Hash Hash of previous snapshot block
    • height : uint64 Height of snapshot block
    • publicKey : ed25519.PublicKey Producer's public key
    • signature : []byte Signature
    • timestamp : time Timestamp of snapshot block produced
    • seed: uint64 Random seed generated by the same producer in prior round
    • nextSeedHash: Hash Hash of random seed generated in current round
    • snapshotData : map[types.Address]HashHeight Snapshot content
  • Example:

# ledger_getSnapshotBlockByHeight

Return snapshot block by height

  • Parameters:

    • uint64 Height of snapshot block
  • Returns: Object : Snapshot block

    • producer : string Snapshot block producer
    • hash : Hash Hash of snapshot block
    • previousHash : Hash Hash of previous snapshot block
    • height : uint64 Height of snapshot block
    • publicKey : ed25519.PublicKey Producer's public key
    • signature : []byte Signature
    • timestamp : time Timestamp of snapshot block produced
    • seed: uint64 Random seed generated by the same producer in prior round
    • nextSeedHash: Hash Hash of random seed generated in current round
    • snapshotData : map[types.Address]HashHeight Snapshot content
  • Example:

# ledger_getChunks

Return snapshot blocks and snapshot account blocks by height range

  • Parameters:

    • string Start height, inclusive
    • string End height, inclusive
  • Returns:

    • SnapshotBlock: Snapshot block
      • producer : string Snapshot block producer
      • hash : Hash Hash of snapshot block
      • previousHash : Hash Hash of previous snapshot block
      • height : uint64 Height of snapshot block
      • publicKey : ed25519.PublicKey Producer's public key
      • signature : []byte Signature
      • timestamp : time Timestamp of snapshot block produced
      • seed: uint64andom seed generated by the same producer in prior round
      • nextSeedHash: Hashash of random seed generated in current round
      • snapshotData : map[types.Address]HashHeight Snapshot content
    • AccountBlocks: Snapshot account blocks. Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getAccountInfoByAddress

Return account info by address

  • Parameters:

    • Address: Account address
  • Return:

  • Example:

# ledger_getLatestSnapshotHash

Return latest snapshot block hash

  • Return:

    • Hash: Hash of latest snapshot block
  • Example:

# ledger_sendRawTransaction

Send a raw transaction by filling in an account block

  • Parameters: Object: AccountBlock Mandatory:

    • blockType: byte Block type
    • height: string Height
    • hash: Hash Hash of AccountBlock
    • previousHash: Hash Hash of previous block in the account chain. Fill 0 if there is no previous block
    • address: Address Account address
    • publicKey: []byte Account's public key
    • signature: []byte Signature

    Optional: below fields should be filled upon sending transaction through pow, otherwise can be ignored or filled with null

    • difficulty: *string PoW difficulty
    • nonce: []byte Nonce

    Optional: below fields should be filled depending on the transaction type (send or receive)

    • sendBlockHash: Hash Hash of corresponding request transaction. Required for response transaction
    • toAddress: Address Account address to send the transaction to. Required for request transaction
    • tokenId: TokenTypeId The token ID in which the transaction is settled. Required for request transaction
    • amount: *string Transaction amount. Required for request transaction
    • fee: *string Transaction fee. Fill "0" or null for all transactions
    • data: []byte Additional data the transaction carries. This field can be specified in request transaction for user account as additional comment or formalized data used to call a contract. Ignore or fill with null if not used.
  • Returns:

    • null
  • Example:

# ledger_getUnreceivedBlocksByAddress

Return all unreceived transactions by address

  • Parameters:

    • Address: Account address
    • uint64: Page index, start with 0
    • uint64: Page size
  • Return:

    • list<AccountBlock>: Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getUnreceivedBlocksInBatch

Return unreceived transactions in batch

  • Parameters:

    • PagingQueryBatch: Account address
      • Address: Account address
      • uint64: Page index, start with 0
      • uint64: Page size
  • Return:

    • map<string Address, list<AccountBlock>> Detail of AccountBlock is described in Common Models
  • Example:

# ledger_getUnreceivedTransactionSummaryByAddress

Return unreceived transaction summary by address

  • Parameters:

    • Address- Account address
  • Return:

  • Example:

# ledger_getUnreceivedTransactionSummaryInBatch

Return unreceived transaction summary in batch

  • Parameters:

    • list<Address>- List of account address
  • Return:

    • list<AccountInfo>: Detail of AccountInfo is described in Common Models
  • Example:

# ledger_getVmLogs

Return event logs generated in the given response block of contract

  • Parameters:

    • Hash: Hash of contract account block
  • Return:

    • List<VmLog>: Event logs
  • Example:

# ledger_getVmLogsByFilter

Return event logs generated in contract response blocks by specified height range and topics

  • Parameters:

    • FilterParam
      • addressHeightRange: map[Address]Range Query logs of the specified contract account address with given range. At least one address must be specified.
        • fromHeight: uint64 Start height. 0 means starting from the latest account block
        • toHeight: uint64 End height. 0 means no specific ending account block
      • topics: [][]Hash Prefix of topics
      • pageIndex: uint64 page index.
      • pageSize: uint64 page size. The value should be less than 1000
  • Returns:

    • Array<VmlogMessage>
    • result: Array<VmlogMessage>
      • accountBlockHash: Hash Hash of account block
      • accountBlockHeight: uint64 Height of account block
      • address: Address Address of account
      • vmlog: VmLog Event log of smart contract
        • topics: Array<string hash> Event signature and indexed field. The signature can be generated from ABI
        • data: string base64 Non-indexed field of event, can be decoded based on ABI
      • removed: bool If true, the log has been rolled back

# ledger_getPoWDifficulty

Return PoW difficulty for sending transaction

This method first calculates the required amount of quota based on transaction parameters, and then determines whether the account has sufficient quota. If no, it returns PoW difficulty that is necessary for sending the transaction.

If the method returns with error, usually it is because the transaction data is too long, or the transaction is not able to obtain quota by calculating PoW. For example, if PoW has been calculated for the previous transaction, the new transaction of the account is not permitted to do PoW again in the same snapshot block.

  • Parameters:

    • GetPoWDifficultyParams
      • address: string address Address of account
      • previousHash: string hash Hash of the previous account block
      • blockType: byte Block type
      • toAddress: string address Address of transaction's recipient, required for request transaction
      • data: string base64 Additional data that the transaction may carry, optional
  • Returns:

    • GetPoWDifficultyResult
      • requiredQuota: string uint64 Quota required for sending the transaction
      • difficulty: string bigint PoW difficulty. If '', sending the transaction does not need PoW
      • qc: string bigint Congestion factor * 1e18
      • isCongestion: bool If true, there is a network congestion. In this case, sending the transaction will consume more quota
  • Example: