Helper Methods
Helper methods during cross-chain transfers

Listen for Cross-Chain Transfer Transaction

Once you have the deposit hash there are two ways of listening for cross-chain transfer transaction.
    1.
    One via SDK where you pass the callback method onFundsTransfered(data) in Hyphen constructor and let SDK call this method whenever a cross-chain transfer happens corresponding to the deposit transaction done by the user via SDK.
    2.
    Or you can call the SDK method checkDepositStatus({depositHash, fromChainId}) manually to check the status of cross-chain transfer for a given depositHash and fromChainId.
Via Callback Method in Contructor
Manually Checking Status via SDK
1
let hyphen = new Hyphen(provider, {
2
// other options here
3
onFundsTransfered: (data) => {
4
/**
5
* data will contain following fields:
6
* fromChainId => Chain id from where funds were transferred
7
* toChainId => Chain id to where funds are transferred
8
* amount => Amount of tokens transferred in smallest unit of token
9
* tokenAddress => Address of token that was trasnferred
10
* depositHash => Deposit transacion hash on fromChainId
11
* exitHash => Transfer transaction hash on toChainId
12
**/
13
}
14
});
Copied!
1
import { RESPONSE_CODES } from "@biconomy/hyphen";
2
const EXIT_STATUS = {
3
PROCESSING: 1,
4
PROCESSED: 2,
5
FAILED: 3
6
}
7
​
8
let depsitHash = "";
9
let fromChainId = 80001;
10
​
11
// Assuming you already have the deposit transaction hash and the chain id
12
// where the transaction was done.
13
​
14
// Periodically call checkDepositStatus method unitll you get the response
15
const response = await hyphen.checkDepositStatus({
16
depositHash: depsitHash,
17
fromChainId: fromChainId
18
});
19
if(response && response.code === RESPONSE_CODES.SUCCESS) {
20
if(response.statusCode === EXIT_STATUS.PROCESSED && response.exitHash) {
21
// βœ… Cross-Chain transfer successfull
22
/**
23
* response will contain following fields:
24
*
25
* fromChainId => Chain id from where funds were transferred
26
* toChainId => Chain id to where funds are transferred
27
* amount => Amount of tokens transferred in smallest unit of token
28
* tokenAddress => Address of token that was trasnferred
29
* depositHash => Deposit transacion hash on fromChainId
30
* exitHash => Transfer transaction hash on toChainId
31
**/
32
} else if(response.statusCode === EXIT_STATUS.PROCESSING && response.exitHash) {
33
// Cross-chain transfer is initiated but transaction is not confirmed yet
34
/**
35
* response will contain following fields:
36
*
37
* fromChainId => Chain id from where funds were transferred
38
* toChainId => Chain id to where funds are transferred
39
* amount => Amount of tokens transferred in smallest unit of token
40
* tokenAddress => Address of token that was trasnferred
41
* depositHash => Deposit transacion hash on fromChainId
42
* exitHash => Transfer transaction hash on toChainId
43
**/
44
}
45
}
46
​
47
​
48
​
Copied!

​

Trigger Cross-Chain Transfer Manually

In case you don't get the transfer transaction hash on the destination chain within few minutes and you are not getting the success response from checkDepositStatus method also, you can manually trigger the cross-chain transfer by calling triggerManualTransfer method.
1
// Assuming you already have the deposit transaction hash on fromChain
2
let depsitHash = "0x.....";
3
let fromChainId = "80001";
4
​
5
let transferStatus = await hyphen.triggerManualTransfer(depsitHash, fromChainId);
6
​
7
if(transferStatus && transferStatus.code === 200 && transferStatus.exitHash) {
8
// Successfuly got the transfer transaction hash on toChain
9
// transferStatus will contain following fields
10
/*
11
* "code": Status code. 200 for success else failure.
12
* "message": Human readable response message.
13
* "exitHash": transaction hash for trasnfer transaction on toChain
14
**/
15
}
Copied!
​
​
Last modified 3mo ago