Check Approve Transaction Status
Check status of approve transaction
Check Approval API
In EVM, TRON and STARKNET blockchains where swap returns a non-null value for approve transaction (e.g. approveData and approveTo fields in case of the EVM), you need to use these values to prepare the approve transaction for the user and call isApproved periodically to see if the approval transaction is completed. After a successful check, you should ask the user to sign the main transaction.
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 the route.
const transaction = await rango.isApproved(
requestId = 'e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b',
txId = '0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f'
)const response = await axios.get('https://api.rango.exchange/basic/is-approved', {
params: {
'requestId': 'e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b',
'txId': '0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f',
'apiKey': 'c6381a79-2817-4602-83bf-6a641a409e32'
}
});curl --request GET \
--url 'https://api.rango.exchange/basic/is-approved?requestId=e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b&txId=0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f&apiKey=c6381a79-2817-4602-83bf-6a641a409e32' You could stop checking is-approved 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* StringDescription: The unique ID which is generated in the best route endpoint.
Example:
e4b0d1e7-ae1f-4aed-ab91-f1ea3ba9383b
txId* StringDescription: Transaction hash that wallet returned for approve transaction.
Example:
0xd7a18c6e2f9afe5aefd1b5969f753513f01c6670a4fc57a2d1349ad539ae2f7f
function isApproved(requestId: string, txId?: string)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) IfisArppovedis false andtxStatusis failed, it means that approve transaction is failed in the blockchain.
requiredApprovedAmountDescription: Required amount to be approved by user
currentApprovedAmountDescription: Current approved amount by 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": "success",
"currentApprovedAmount": "0.903658",
"requiredApprovedAmount": "0.903658"
}Last updated
Was this helpful?