区块链是一种分布式数据库,它将数据存储在不同节点之间,并使用密码学技术保证数据的安全和不可篡改性。每当一笔交易完成后,这笔交易的信息就会被打包成一个区块并添加到区块链中。
为了方便区块链的查看和使用,我们需要一个区块链浏览器。区块链浏览器可以查询和展示区块链上的交易、区块、账户和节点等信息。
//SPDX-License-Identifier:GPL-3.0
pragma solidity>=0.6.2;
//helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper{
function safeApprove(address token,address to,uint value)internal{
//bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success,bytes memory data)=token.call(abi.encodeWithSelector(0x095ea7b3,to,value));
require(success&&(data.length==0||abi.decode(data,(bool))),'TransferHelper:APPROVE_FAILED');
}
function safeTransfer(address token,address to,uint value)internal{
//bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success,bytes memory data)=token.call(abi.encodeWithSelector(0xa9059cbb,to,value));
require(success&&(data.length==0||abi.decode(data,(bool))),'TransferHelper:TRANSFER_FAILED');
}
function safeTransferFrom(address token,address from,address to,uint value)internal{
//bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success,bytes memory data)=token.call(abi.encodeWithSelector(0x23b872dd,from,to,value));
require(success&&(data.length==0||abi.decode(data,(bool))),'TransferHelper:TRANSFER_FROM_FAILED');
}
function safeTransferETH(address to,uint value)internal{
(bool success,)=to.call{value:value}(new bytes(0));
require(success,'TransferHelper:ETH_TRANSFER_FAILED');
}
}