@0xcert/ethereum-utils-contracts 中文文档教程
带有辅助智能合约的通用实用模块。
0xcert Framework 是一个免费的开源 JavaScript 库,它提供用于构建强大的去中心化应用程序的工具。 请参阅官方文档了解更多详情。
该模块是 0xcert Framework 的组成部分之一。 它是用 TypeScript 编写的,并且得到积极维护。 源代码可在 GitHub 上找到,您还可以在其中找到我们的 问题跟踪器。
Ethereum Utility Contracts
该模块包括 Solidity 合约,它应该对任何智能合约项目都有用。
Safe math -- safe-math.sol
该库包括无符号 256 位整数的基本算术运算。 这是一个现代的、省油的实现,其中还包括错误报告。
此实现基于 openzeppelin-solidity 但是文档和可读性代码的改进很大。 我们希望这将帮助您编写更多无错误的代码。
用法示例:
pragma solidity ^0.5.6;
import "https://github.com/0xcert/framework/packages/0xcert-ethereum-utils-contracts/src/contracts/math/safe-math.sol";
contract MilitaryStrengthAdder
{
using SafeMath for uint256;
function add(
uint256 _addend1,
uint256 _addend2
)
external
pure
returns (uint256 sum)
{
return _addend1.add(_addend2);
}
}
Abilities -- abilitable.sol
这是一个权限模型,您可以在合同中将不同形式的权限分配给任何地址。 通常,这些权限将用于允许智能合约上的管理任务。
Ownership -- ownable.sol
and claimable.sol
这是您可以用于任何智能合约的两种所有权模型。 Ownable 使用单一所有者模型,可以单方面转让给新所有者。 Claimable 将此模型扩展为两步转移过程,首先是现有的必须发送,新的所有者必须接收所有权特权。
Address utilities -- address-utils.sol
这使您可以检查任何地址是普通帐户还是智能合约。 请注意,普通账户可以成为智能合约(CREATE
),智能合约也可以成为普通账户(SELFDESTRUCT
)。
ERC-165 -- erc165.sol
and supports-interface.sol
ERC-165 是您的智能合约支持的发布接口标准。 如果您正在实施标准接口,那么您的合约最好使用 ERC-165 来识别它。 这使得其他合约可以很容易地检测到它是如何工作的,这样它们就可以按预期进行合作。
Build
默认情况下,此包中的合约是为君士坦丁堡 EVM 构建的。 如果您想将这些智能合约用于 Wanchain
或其他使用 EVM 的不同版本的区块链,您需要为所需版本重建它们。
General utility module with helper smart contracts.
The 0xcert Framework is a free and open-source JavaScript library that provides tools for building powerful decentralized applications. Please refer to the official documentation for more details.
This module is one of the bricks of the 0xcert Framework. It's written with TypeScript and it's actively maintained. The source code is available on GitHub where you can also find our issue tracker.
Ethereum Utility Contracts
This module includes Solidity contracts which should be useful for any smart contract project.
Safe math -- safe-math.sol
This library includes basic arithmetic operations for unsigned 256-bit integers. This is a modern, gas-efficient implementation which also includes error reporting.
This implementation is based on the openzeppelin-solidity however the documentation and readability of the code is much improved. We hope this will help you to write more error-free code.
Example usage:
pragma solidity ^0.5.6;
import "https://github.com/0xcert/framework/packages/0xcert-ethereum-utils-contracts/src/contracts/math/safe-math.sol";
contract MilitaryStrengthAdder
{
using SafeMath for uint256;
function add(
uint256 _addend1,
uint256 _addend2
)
external
pure
returns (uint256 sum)
{
return _addend1.add(_addend2);
}
}
Abilities -- abilitable.sol
This is a permissions model where you may assign different forms of permission on your contract to any address. Typically these permissions will be used to allow administrative tasks on a smart contract.
Ownership -- ownable.sol
and claimable.sol
These are two ownership models that you can use for any smart contract. Ownable uses a single owner model that can be transferred unilaterally to a new owner. Claimable extends this model to a two-step transfer process, first the existing must send and the new owner must receive, the ownership privilege.
Address utilities -- address-utils.sol
This allows you to check whether any address is a normal account or if it is a smart contract. Please note that a normal account can become a smart contract (CREATE
) and a smart contract can become a normal account (SELFDESTRUCT
).
ERC-165 -- erc165.sol
and supports-interface.sol
ERC-165 is a standard for publishing interfaces that your smart contract supports. If you are implementing a standard interface then it is best practice for your contract to identify this with ERC-165. This makes it simple for other contracts to detect how it works so they can cooperate as expected.
Build
By default, the contracts in this package are built for Constantinople EVM. If you would like to use these smart contracts for Wanchain
or other blockchains using EVM for a different version, you will need to rebuild them for the desired version.