â—† Purpose

to transfer token.

And this code allows not to import library. This is lead to saving the gas

👇 Why you can save gas fee without importing library

https://medium.com/coinmonks/gas-cost-of-solidity-library-functions-dbe0cedd4678

â—† Input & Return value

(address token, address to, uint value) ⇒ none

â—† Example

token: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2(WETH)

to: 0xED98485593D5865E892f823e1f66FB99fE64F639(my wallet address)

value: 1234567

â—† Code and Explain

Solidity code works on EVM.

EVM get the target function by 4bytes.

Convert sol unit

EVM judges the 4bytes to select function

4bytes = 8 hex(0x12345678) ⇒ FunctionID

bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
function _safeTransfer(address token, address to, uint value) private {
				// call is one of the method to send token. returns bool and bytes 	
        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
        require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}

â—† Resources