๐Ÿช™
Transfer ETH
Transfer Native assets on any blockchain - ETH (Ethereum), BNB (Binance Smart Chain), MATIC (Polygon)

Transfer Native Assets (ETH/BNB/MATIC etc)

To transfer native assets of the blockchain follow the steps:
  1. 1.
    Construct anoptionsobject and set
    1. 1.
      type:"native"
    2. 2.
      amount: "3425435345" //inweiโ€‹
    3. 3.
      receiver: "0x000..." //wallet address
  2. 2.
    Call the Moralis transfer function as shown below
JS
React
1
// sending 0.5 ETH
2
const options = {
3
type: "native",
4
amount: Moralis.Units.ETH("0.5"),
5
receiver: "0x..",
6
};
7
let result = await Moralis.transfer(options);
Copied!
1
import React from "react";
2
import { useWeb3Transfer } from "react-moralis";
3
โ€‹
4
const TransferEth = () => {
5
const { fetch, error, isFetching } = useWeb3Transfer({
6
type: "native",
7
amount: Moralis.Units.ETH(0.5),
8
receiver: "0x0000000000000000000000000000000000000000",
9
});
10
โ€‹
11
return (
12
// Use your custom error component to show errors
13
<div>
14
{error && <ErrorMessage error={error} />}
15
<button onClick={() => fetch()} disabled={isFetching}>
16
Transfer
17
</button>
18
</div>
19
);
20
};
Copied!
Use Moralis.Units.ETH to specify the amount in ETH (same goes for BSC and Polygon).
โ€‹Moralis.Units.ETHis a helper function that will convert your ETH amount to wei which is required in order to construct the transaction.

Resolving the results

Moralis.transfer() returns a transaction response after it is executed. The below page shows how to consume the data returned.