Tx

tx_sendRawTx

Send a raw transaction block

  • Parameters: Object : RawTxBlock

    Mandatory:

    • blockType : byte Block type
    • height : string Height
    • hash : Hash Transaction hash
    • prevHash : Hash The hash of previous block in the account chain. Fill 0 if there is no previous block
    • accountAddress : 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)

    • fromBlockHash : Hash The hash of corresponding request transaction. Required for response transaction
    • toAddress : Address The 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: Object : AccountBlock

    • blockType : byte
    • height : string
    • hash : Hash
    • prevHash : Hash
    • accountAddress : Address
    • publicKey : []byte
    • signature : []byte
    • fromAddress : Address
    • toAddress : Address
    • fromBlockHash : Hash
    • tokenId : TokenTypeId
    • amount : *string
    • fee : *string
    • data : []byte
    • difficulty : *string
    • nonce : []byte
    • quota : *string The quota of the account
    • quotaUsed : *string The quota consumed by the transaction
    • logHash : *types.Hash The hash of LogList generated by smart contract
    • sendBlockList : []*RawTxBlock A list of request transactions sent from within the block. RS block only
    • tokenInfo : *RpcTokenInfo The token information in which the transaction is settled
    • confirmedTimes : *string The confirmation number of the transaction
    • confirmedHash : *Hash The hash of snapshot block in which the transaction was snapshotted
    • timestamp : int64 The timestamp(seconds) in which the transaction was snapshotted
    • receiveBlockHeight : *string The height of the corresponding response transaction. Request transaction only
    • receiveBlockHash : *Hash The hash of the corresponding response transaction. Request transaction only
  • Example:

{
    "jsonrpc": "2.0",
    "id": 17,
    "method": "tx_sendRawTx",
    "params": [{
    	"blockType": 2,
        "height": "9",
        "hash": "7161f621d1bdc2571fa1e66917fca90b047e3e5c78c18e5cfb11edba32c7c2fc",
        "prevHash": "7c6a8b729e73ae98409a5ab72ccc458ff449eced5e7ee757d52de83e8f32a070",
        "accountAddress": "vite_ab24ef68b84e642c0ddca06beec81c9acb1977bbd7da27a87a",
        "publicKey": "WHZinxslscE+WaIqrUjGu2scOvorgD4Q+DQOOcDBv4M=",
        "signature":"Hz8bC6TUM00oWylUua7oN2sE4EEFUuCK4C9LQcZZu8vyb3UU9xG32BeJtBQ==",
        "difficulty": "65535",
        "nonce": "Tgb+PebmE4w=",
        "fromBlockHash": "0000000000000000000000000000000000000000000000000000000000000000",
        "toAddress":"vite_ab24ef68b84e642c0ddca06beec81c9acb1977bbd7da27a87a",
        "tokenId": "tti_5649544520544f4b454e6e40",
        "amount": "10000",
        "fee": "0",
        "data":null
    }]
}
{
    "jsonrpc": "2.0",
    "id": 17,
    "method": "tx_sendRawTx",
    "params": [{
    	"blockType": 4,
        "height": "11",
        "hash": "d7a26855f131f53ba6320f0ebcba99f2c2157d60a47dc7a53a3186cd0b202b63",
        "prevHash": "9f463b7db51f91951de9445570e4a6d4f00def4d528c80ddfdf39e1e47f8498d",
        "accountAddress": "vite_ab24ef68b84e642c0ddca06beec81c9acb1977bbd7da27a87a",
        "publicKey": "WHZinxslscE+WaIqrUjGu2scOvorgD4Q+DQOOcDBv4M=",
        "signature":"zBF5LgOOxQ+H86oMNQ3kbuJbiQ+yCdLbtOdmEJ7QRNo67HF3b/pm+bfM5EHuxMNpOnimKgawtozZwifnFVhyDQ==",
        "difficulty": null,
        "nonce": null,
        "fromBlockHash":"7c6a8b729e73ae98409a5ab72ccc458ff449eced5e7ee757d52de83e8f32a070",
        "data":null
    }]
}
{
    "jsonrpc": "2.0",
    "id": 17,
    "result": null
}
{
    "jsonrpc": "2.0",
    "id": 17,
    "error": {
        "code": -36006,
        "message": "verify prevBlock failed, incorrect use of prevHash or fork happened"
    }
}

tx_calcPoWDifficulty

Obtain current PoW difficulty for sending a transaction via sendRawTx .

This method calculates the required quota based on given transaction parameters, and then determines whether the account has enough quota from staking. Difficulty is only calculated if the account does not have sufficient quota. If error returns, it means that the current transaction cannot obtain quota by calculating PoW. For example, during the same snapshot period, if previous transaction in the account chain has obtained quota through calculating PoW, calling this method for next transaction will throw an error.

  • Parameters:

    • selfAddr : Address Account address
    • prevHash : Hash The hash of previous block in the account chain. Fill 0 if there is no previous block
    • blockType : byte Transaction type
    • toAddr : Address The account address to send the transaction to. Required for request transaction. Fill null for response.
    • data : []byte Additional data the transaction carries
    • usePledgeQuota : bool Whether quota from staking is used first
  • Returns: Object

    • difficulty : big.Int Current PoW difficulty. Empty string means calculating PoW is not necessary
    • quota : uint64 Quota that will be consumed by the transaction
  • Example:

{
	"jsonrpc": "2.0",
	"id": 17,
	"method": "tx_calcPoWDifficulty",
	"params": [{
		"selfAddr":"vite_bb6ad02107a4422d6a324fd2e3707ad53cfed9359378a78792",
		"prevHash":"51ee7ce9c6218eee0e98551ebfa46255dfbd9c40bf73c4b69622ff90e5b8d153",
		"blockType":4,
		"toAddr":"vite_bb6ad02107a4422d6a324fd2e3707ad53cfed9359378a78792",
		"data":"8pxs4gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAACA1EbeCzJnsDy6fZtJr6XnE0HHzQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFc3VwZXIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
		"usePledgeQuota":true
	}]
}
{
    "jsonrpc": "2.0",
    "id": 17,
    "result": {
        "quota": 21000,
        "difficulty": "65534"
    }
}