Skip to content

Latest commit

 

History

History
417 lines (278 loc) · 18.7 KB

TransactionsApi.md

File metadata and controls

417 lines (278 loc) · 18.7 KB

aptos_api_dart.api.TransactionsApi

Load the API package

import 'package:aptos_api_dart/api.dart';

All URIs are relative to https://raw.githubusercontent.com/v1

Method HTTP request Description
encodeSubmission POST /transactions/encode_submission Encode submission
estimateGasPrice GET /estimate_gas_price Estimate gas price
getAccountTransactions GET /accounts/{address}/transactions Get account transactions
getTransactionByHash GET /transactions/by_hash/{txn_hash} Get transaction by hash
getTransactionByVersion GET /transactions/by_version/{txn_version} Get transaction by version
getTransactions GET /transactions Get transactions
simulateTransaction POST /transactions/simulate Simulate transaction
submitBatchTransactions POST /transactions/batch Submit batch transactions
submitTransaction POST /transactions Submit transaction

encodeSubmission

String encodeSubmission(encodeSubmissionRequest)

Encode submission

This endpoint accepts an EncodeSubmissionRequest, which internally is a UserTransactionRequestInner (and optionally secondary signers) encoded as JSON, validates the request format, and then returns that request encoded in BCS. The client can then use this to create a transaction signature to be used in a SubmitTransactionRequest, which it then passes to the /transactions POST endpoint. To be clear, this endpoint makes it possible to submit transaction requests to the API from languages that do not have library support for BCS. If you are using an SDK that has BCS support, such as the official Rust, TypeScript, or Python SDKs, you do not need to use this endpoint. To sign a message using the response from this endpoint: - Decode the hex encoded string in the response to bytes. - Sign the bytes to create the signature. - Use that as the signature field in something like Ed25519Signature, which you then use to build a TransactionSignature.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final EncodeSubmissionRequest encodeSubmissionRequest = ; // EncodeSubmissionRequest | 

try {
    final response = api.encodeSubmission(encodeSubmissionRequest);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->encodeSubmission: $e\n');
}

Parameters

Name Type Description Notes
encodeSubmissionRequest EncodeSubmissionRequest

Return type

String

Authorization

No authorization required

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

estimateGasPrice

GasEstimation estimateGasPrice()

Estimate gas price

Gives an estimate of the gas unit price required to get a transaction on chain in a reasonable amount of time. The gas unit price is the amount that each transaction commits to pay for each unit of gas consumed in executing the transaction. The estimate is based on recent history: it gives the minimum gas that would have been required to get into recent blocks, for blocks that were full. (When blocks are not full, the estimate will match the minimum gas unit price.) The estimation is given in three values: de-prioritized (low), regular, and prioritized (aggressive). Using a more aggressive value increases the likelihood that the transaction will make it into the next block; more aggressive values are computed with a larger history and higher percentile statistics. More details are in AIP-34.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();

try {
    final response = api.estimateGasPrice();
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->estimateGasPrice: $e\n');
}

Parameters

This endpoint does not need any parameter.

Return type

GasEstimation

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

getAccountTransactions

BuiltList getAccountTransactions(address, start, limit)

Get account transactions

Retrieves on-chain committed transactions from an account. If the start version is too far in the past, a 410 will be returned. If no start version is given, it will start at version 0. To retrieve a pending transaction, use /transactions/by_hash.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final String address = address_example; // String | Address of account with or without a `0x` prefix
final String start = start_example; // String | Account sequence number to start list of transactions  If not provided, defaults to showing the latest transactions
final int limit = 56; // int | Max number of transactions to retrieve.  If not provided, defaults to default page size

try {
    final response = api.getAccountTransactions(address, start, limit);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->getAccountTransactions: $e\n');
}

Parameters

Name Type Description Notes
address String Address of account with or without a 0x prefix
start String Account sequence number to start list of transactions If not provided, defaults to showing the latest transactions [optional]
limit int Max number of transactions to retrieve. If not provided, defaults to default page size [optional]

Return type

BuiltList<Transaction>

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

getTransactionByHash

Transaction getTransactionByHash(txnHash)

Get transaction by hash

Look up a transaction by its hash. This is the same hash that is returned by the API when submitting a transaction (see PendingTransaction). When given a transaction hash, the server first looks for the transaction in storage (on-chain, committed). If no on-chain transaction is found, it looks the transaction up by hash in the mempool (pending, not yet committed). To create a transaction hash by yourself, do the following: 1. Hash message bytes: "RawTransaction" bytes + BCS bytes of Transaction. 2. Apply hash algorithm SHA3-256 to the hash message bytes. 3. Hex-encode the hash bytes with 0x prefix.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final String txnHash = txnHash_example; // String | Hash of transaction to retrieve

try {
    final response = api.getTransactionByHash(txnHash);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->getTransactionByHash: $e\n');
}

Parameters

Name Type Description Notes
txnHash String Hash of transaction to retrieve

Return type

Transaction

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

getTransactionByVersion

Transaction getTransactionByVersion(txnVersion)

Get transaction by version

Retrieves a transaction by a given version. If the version has been pruned, a 410 will be returned.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final String txnVersion = txnVersion_example; // String | Version of transaction to retrieve

try {
    final response = api.getTransactionByVersion(txnVersion);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->getTransactionByVersion: $e\n');
}

Parameters

Name Type Description Notes
txnVersion String Version of transaction to retrieve

Return type

Transaction

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

getTransactions

BuiltList getTransactions(start, limit)

Get transactions

Retrieve on-chain committed transactions. The page size and start ledger version can be provided to get a specific sequence of transactions. If the version has been pruned, then a 410 will be returned. To retrieve a pending transaction, use /transactions/by_hash.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final String start = start_example; // String | Ledger version to start list of transactions  If not provided, defaults to showing the latest transactions
final int limit = 56; // int | Max number of transactions to retrieve.  If not provided, defaults to default page size

try {
    final response = api.getTransactions(start, limit);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->getTransactions: $e\n');
}

Parameters

Name Type Description Notes
start String Ledger version to start list of transactions If not provided, defaults to showing the latest transactions [optional]
limit int Max number of transactions to retrieve. If not provided, defaults to default page size [optional]

Return type

BuiltList<Transaction>

Authorization

No authorization required

HTTP request headers

  • Content-Type: Not defined
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

simulateTransaction

BuiltList simulateTransaction(submitTransactionRequest, estimateMaxGasAmount, estimateGasUnitPrice, estimatePrioritizedGasUnitPrice)

Simulate transaction

The output of the transaction will have the exact transaction outputs and events that running an actual signed transaction would have. However, it will not have the associated state hashes, as they are not updated in storage. This can be used to estimate the maximum gas units for a submitted transaction. To use this, you must: - Create a SignedTransaction with a zero-padded signature. - Submit a SubmitTransactionRequest containing a UserTransactionRequest containing that signature. To use this endpoint with BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final SubmitTransactionRequest submitTransactionRequest = ; // SubmitTransactionRequest | 
final bool estimateMaxGasAmount = true; // bool | If set to true, the max gas value in the transaction will be ignored and the maximum possible gas will be used
final bool estimateGasUnitPrice = true; // bool | If set to true, the gas unit price in the transaction will be ignored and the estimated value will be used
final bool estimatePrioritizedGasUnitPrice = true; // bool | If set to true, the transaction will use a higher price than the original estimate.

try {
    final response = api.simulateTransaction(submitTransactionRequest, estimateMaxGasAmount, estimateGasUnitPrice, estimatePrioritizedGasUnitPrice);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->simulateTransaction: $e\n');
}

Parameters

Name Type Description Notes
submitTransactionRequest SubmitTransactionRequest
estimateMaxGasAmount bool If set to true, the max gas value in the transaction will be ignored and the maximum possible gas will be used [optional]
estimateGasUnitPrice bool If set to true, the gas unit price in the transaction will be ignored and the estimated value will be used [optional]
estimatePrioritizedGasUnitPrice bool If set to true, the transaction will use a higher price than the original estimate. [optional]

Return type

BuiltList<UserTransaction>

Authorization

No authorization required

HTTP request headers

  • Content-Type: application/json, application/x.aptos.signed_transaction+bcs
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

submitBatchTransactions

TransactionsBatchSubmissionResult submitBatchTransactions(submitTransactionRequest)

Submit batch transactions

This allows you to submit multiple transactions. The response has three outcomes: 1. All transactions succeed, and it will return a 202 2. Some transactions succeed, and it will return the failed transactions and a 206 3. No transactions succeed, and it will also return the failed transactions and a 206 To submit a transaction as JSON, you must submit a SubmitTransactionRequest. To build this request, do the following: 1. Encode the transaction as BCS. If you are using a language that has native BCS support, make sure to use that library. If not, you may take advantage of /transactions/encode_submission. When using this endpoint, make sure you trust the node you're talking to, as it is possible they could manipulate your request. 2. Sign the encoded transaction and use it to create a TransactionSignature. 3. Submit the request. Make sure to use the "application/json" Content-Type. To submit a transaction as BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs. Make sure to use the application/x.aptos.signed_transaction+bcs Content-Type.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final BuiltList<SubmitTransactionRequest> submitTransactionRequest = ; // BuiltList<SubmitTransactionRequest> | 

try {
    final response = api.submitBatchTransactions(submitTransactionRequest);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->submitBatchTransactions: $e\n');
}

Parameters

Name Type Description Notes
submitTransactionRequest BuiltList<SubmitTransactionRequest>

Return type

TransactionsBatchSubmissionResult

Authorization

No authorization required

HTTP request headers

  • Content-Type: application/json, application/x.aptos.signed_transaction+bcs
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]

submitTransaction

PendingTransaction submitTransaction(submitTransactionRequest)

Submit transaction

This endpoint accepts transaction submissions in two formats. To submit a transaction as JSON, you must submit a SubmitTransactionRequest. To build this request, do the following: 1. Encode the transaction as BCS. If you are using a language that has native BCS support, make sure of that library. If not, you may take advantage of /transactions/encode_submission. When using this endpoint, make sure you trust the node you're talking to, as it is possible they could manipulate your request. 2. Sign the encoded transaction and use it to create a TransactionSignature. 3. Submit the request. Make sure to use the "application/json" Content-Type. To submit a transaction as BCS, you must submit a SignedTransaction encoded as BCS. See SignedTransaction in types/src/transaction/mod.rs. Make sure to use the application/x.aptos.signed_transaction+bcs Content-Type.

Example

import 'package:aptos_api_dart/api.dart';

final api = AptosApiDart().getTransactionsApi();
final SubmitTransactionRequest submitTransactionRequest = ; // SubmitTransactionRequest | 

try {
    final response = api.submitTransaction(submitTransactionRequest);
    print(response);
} catch on DioError (e) {
    print('Exception when calling TransactionsApi->submitTransaction: $e\n');
}

Parameters

Name Type Description Notes
submitTransactionRequest SubmitTransactionRequest

Return type

PendingTransaction

Authorization

No authorization required

HTTP request headers

  • Content-Type: application/json, application/x.aptos.signed_transaction+bcs
  • Accept: application/json, application/x-bcs

[Back to top] [Back to API list] [Back to Model list] [Back to README]