Check Approve Transaction Status
Check status of approve transaction
Check Approval Status API
When createTransaction returns an approval transaction (i.e. isApprovalfield is true in transaction), and the user signs that transaction, you could periodically call check-approval to see if the approval transaction is completed. After a successful check, you should call createTransaction again to receive the main transaction.
const transaction = await rango.checkApproval({
requestId: "b3a12c6d-86b8-4c21-97e4-809151dd4036", // bestRoute.requestId
txId: "0x7f17aaba51d1f24204cd8b02251001d3704add46d84840a5826b95ef49b8b74f" // optional
})const response = await axios.get('https://api.rango.exchange/tx/b3a12c6d-86b8-4c21-97e4-809151dd4036/check-approval', {
params: {
'txId': '0x7f17aaba51d1f24204cd8b02251001d3704add46d84840a5826b95ef49b8b74f',
'apiKey': 'c6381a79-2817-4602-83bf-6a641a409e32'
}
});curl --request GET \
--url 'https://api.rango.exchange/tx/b3a12c6d-86b8-4c21-97e4-809151dd4036/check-approval?txId=0x7f17aaba51d1f24204cd8b02251001d3704add46d84840a5826b95ef49b8b74f&apiKey=c6381a79-2817-4602-83bf-6a641a409e32' Caution
It is important to use approve transaction data generated by Rango API and not hard-coding something on your client side for creating approve transaction, because for some protocols (some bridges), the contract that should be approved is dynamically generated via their API based on route.
You could stop checking approval method if:
Approval transaction succeeded. =>
isApproved === trueApproval transaction failed. =>
!isApproved && txStatus === 'failed'Approval transaction succeeded but
currentApprovedAmountis still less thanrequiredApprovedAmount(e.g. user changed transaction data in wallet and enter another approve amount in MetaMask instead of default approve amount proposed by Rango API) =>!isApproved && txStatus === 'success'
Check Approval Request
requestId*Description: The unique ID which is generated in the best route endpoint.
Example:
b3a12c6d-86b8-4c21-97e4-809151dd4036
txIdDescription: Transaction hash returned by wallet
Example:
0x7f17aaba51d1f24204cd8b02251001d3704add46d84840a5826b95ef49b8b74f
public async checkApproval(
requestId: string,
txId?: string
): Promise<CheckApprovalResponse>;Check Approval Response
isApprovedDescription: A flag which indicates that the approve tx is done or not.
txStatusDescription: Status of approve transaction in blockchain (possible values are
success,runningandfailed)if
isArppovedis false andtxStatusisfailed, it means that approve transaction is failed in the blockchain.
currentApprovedAmountDescription: Required amount to be approved by the user.
requiredApprovedAmountDescription: Current approved amount by the user.
export type CheckApprovalResponse = {
isApproved: boolean
txStatus: TransactionStatus | null
requiredApprovedAmount: string | null
currentApprovedAmount: string | null
}
export enum TransactionStatus {
FAILED = 'failed',
RUNNING = 'running',
SUCCESS = 'success',
}{
"isApproved": true,
"txStatus": "suuccess",
"currentApprovedAmount": 100020003000,
"requiredApprovedAmount": 100020003000
}Last updated
Was this helpful?