Transfer
- React
- React-Native
- TypeScript
- Unity
useTransfer
Hook for transferring tokens on an ERC20 contract.
Available to use on contracts that implement the ERC20 interface, such as the Token contract.
The wallet address that initiates this transaction must have a balance of tokens greater than or equal to the amount being transferred.
import { useTransferToken } from "@thirdweb-dev/react";
const { mutate, isLoading, error } = useTransferToken(contract);
Usage
Provide your ERC20 contract as an argument to the hook.
import { useContract, useTransferToken, Web3Button } from "@thirdweb-dev/react";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
Configuration
to (required)
to (required)
The wallet address to transfer tokens to.
import { useContract, useTransferToken, Web3Button } from "@thirdweb-dev/react";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
amount (required)
amount (required)
The quantity of tokens to transfer. Can be a string
or number
.
import { useContract, useTransferToken, Web3Button } from "@thirdweb-dev/react";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
useTransfer
Hook for transferring tokens on an ERC20 contract.
Available to use on contracts that implement the ERC20 interface, such as the Token contract.
The wallet address that initiates this transaction must have a balance of tokens greater than or equal to the amount being transferred.
import { useTransferToken } from "@thirdweb-dev/react-native";
const { mutate, isLoading, error } = useTransferToken(contract);
Usage
Provide your ERC20 contract as an argument to the hook.
import {
useContract,
useTransferToken,
Web3Button,
} from "@thirdweb-dev/react-native";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
Configuration
to (required)
to (required)
The wallet address to transfer tokens to.
import {
useContract,
useTransferToken,
Web3Button,
} from "@thirdweb-dev/react-native";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
amount (required)
amount (required)
The quantity of tokens to transfer. Can be a string
or number
.
import {
useContract,
useTransferToken,
Web3Button,
} from "@thirdweb-dev/react-native";
const contractAddress = "{{contract_address}}";
const toAddress = "{{to_address}}";
const amount = "{{amount}}";
function App() {
// Contract must be an ERC-20 contract
const { contract } = useContract(contractAddress);
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);
return (
<Web3Button
contractAddress={contractAddress}
action={() =>
transferTokens({
to: toAddress, // Address to transfer to
amount: amount, // Amount to transfer
})
}
>
Transfer
</Web3Button>
);
}
transfer
Transfer native or ERC20 tokens from this wallet to another wallet
// for native tokens
const txResult = await wallet.transfer(recipientAddress, amount);
// for ERC20 tokens
const txResult = await wallet.transfer(recipientAddress, amount, tokenAddress);
recipientAddress
Address of the recipient to send the tokens to
string
amount
Amount of tokens to send
string | number
Return Value
Promise<TransactionResult>
Transfer
Transfer native or ERC20 tokens from this wallet to another wallet.
Usage
var data = await sdk.wallet.Transfer("{{to_address}}", "{{amount}}");
Configuration
to
The address of the account to send funds to.
Must be a string
.
amount
The amount in tokens to be transferred.
Must be a string
.
currencyAddress (optional)
The address of the token smart contract that you want to transfer.
If no address is provided, the native currency will be used.
Must be a string
.
var data = await sdk.wallet.Transfer("{{to_address}}", "{{amount}}", "{{currency_contract_address}}")