TransferTokens
This function triggers a modal for the user to confirm the transfer
Function to trigger a transfer for a native or ERC20 token. This will trigger a confirmation modal displaying a summary of the transaction and associated fees for the user.
TransferTokens(args)
Parameter | Type | Definition |
---|---|---|
args.callback? | Function | Function to callback upon txhash, success or failed transfer.
Structure of result object passed into callback function: 1 { 2 "status": "TXHASH", // "TXHASH"/"SUCCESS"/"FAILED" 3 "errorMsg": "", 4 "txHash": "0xec90b7c220b1d9550c202ed7adb7db97be2b8c8b9f422bb2d3c555498d95ef49", 5 "from": "0xb8E46105a6F11E3250837897b3A10450716b28d8", 6 "to": "0xfFEaf294116b610d0cdD4afaAfe861563c72BB76", 7 "amount": "0.1", 8 "currency": Object // type Currency class 9 } |
args.to? | String | Address to send tokens to. If not passed in, will prompt user to enter address. |
args.amount? | String | Amount to send in display units of the currency. So if you want the user to pay 0.5 ETH, pass in '0.5' to this field. If value not passed in, will prompt user to pass in the amount |
args.currency? | asset (class) | Asset object of the currency you want to send. If value not passed in, will prompt user to pass in the currency |
None
Calling transfer without args
1
import { useMetafi } from '@metafi/react-sdk';
2
3
function App() {
4
const { TransferTokens } = useMetafi();
5
6
const transfer = () => {
7
TransferTokens(res => console.log("received result from transfer", res));
8
};
9
10
return (
11
<>
12
<button onClick={transfer}>Transfer ETH</button>
13
</>
14
);
15
};
Calling transfer with args
1
import { useMetafi, assets } from '@metafi/react-sdk';
2
3
function App() {
4
const { TransferTokens } = useMetafi();
5
6
const transfer = () => {
7
TransferTokens({
8
userIdentifier: "12345",
9
callback: (res) => {
10
console.log("received result from transfer", res)
11
},
12
"to": "0xfFEaf294106b630d0cdD4afaAfe861563c72BB76", // to
13
"amount": "0.1", // amount in display unit
14
"currency": assets.eth, // currency
15
});
16
};
17
18
return (
19
<>
20
<button onClick={transfer}>Transfer ETH</button>
21
</>
22
);
23
};
Last modified 3mo ago