TransferHelper
This library provides helper methods for interacting with ERC20 tokens and sending ETH. These methods ensure safe and reliable token transfers by checking the success of the transfer operations.
Internal Functions
safeApprove
safeApprove
Safely approves the specified to
address to spend the specified value
amount of tokens from the token
contract. It uses the approve
function of the ERC20 token.
Parameters
token
address
The address of the ERC20 token contract.
to
address
The address to approve for spending the tokens.
value
uint
The amount of tokens to approve.
safeTransfer
safeTransfer
Safely transfers the specified value
amount of tokens from the caller's address to the to
address. It uses the transfer
function of the ERC20 token.
Parameters
token
address
The address of the ERC20 token contract.
to
address
The address to which the tokens should be transferred.
value
uint
The amount of tokens to transfer.
safeTransferFrom
safeTransferFrom
Safely transfers the specified value
amount of tokens from the from
address to the to
address. It uses the transferFrom
function of the ERC20 token.
Parameters
token
address
The address of the ERC20 token contract.
from
address
The address from which the tokens should be transferred.
to
address
The address to which the tokens should be transferred.
value
uint
The amount of tokens to transfer.
safeTransferETH
safeTransferETH
Safely sends the specified value
amount of Ether to the to
address.
Parameters
to
address
The address to which the Ether should be sent.
value
uint
The amount of Ether to send.
decimals
decimals
Retrieves the number of decimal places used by the specified ERC20 token
contract.
Parameters
token
address
The address of the ERC20 token contract.
Returns
decimals
uint8
The number of decimal places used by the token.
Last updated