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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
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
Name | Type | Description |
---|---|---|
token | address | The address of the ERC20 token contract. |
Returns
Name | Type | Description |
---|---|---|
decimals | uint8 | The number of decimal places used by the token. |
Last updated