@1001-digital/check-address 中文文档教程
Check Address
用于以太坊区块链的 Solidity 库,可轻松区分智能合约和外部地址。
警告:可以通过从合约构造函数中调用来规避此库中的检查。 有关详细的攻击示例,请参阅测试并查看 this discussion 探索这个问题。
仔细考虑这在您的用例中是否可以接受。
Installation
- In your project run
npm install @1001-digital/check-address
- Within your contract, import the library
import "@1001-digital/check-address/contracts/CheckAddress.sol";
- In your code, you can check address types like so:
address account = 0x1234567891011121314151617181920212223242
if (CheckAddress.isExternal(account)) {
// ...
}
注意:您必须在开发期间创建合同时链接库:
const CheckAddress = await ethers.getContractFactory('CheckAddress');
const library = await CheckAddress.deploy()
const MyContract = await ethers.getContractFactory('MyContract', {
libraries: {
CheckAddress: library.address,
},
});
Local Development
要设置您的环境,请运行 npm install
。
注意:如果你的系统全局安装了 hh
,你可以将 npm run
换成 hh
。
- Run the test suite:
npm run test
- Spin up a local development blockchain:
npm run node
- Deploy the contract with
npm run deploy:localhost
Deployment
通过 npm run deploy:{NETWORK}
部署项目,NETWORK
是 localhost|rinkeby|ropsten|mainnet
之一。
Live Deployments
- Mainnet: TODO
- Ropsten:
0x87f11cba2Db0cB22b9679c14860bA5Be49Fd0717
- Rinkeby:
0x029374cA831F9F4B04a0D896B8d00CcE05f30D8f
Thank You
如果您有任何改进建议、反馈或错误报告,请随时添加问题,或通过 Twitter @jwahdatehagh 或电子邮件 jalil@1001.digital。
Check Address
A Solidity library for the Ethereum blockchain to easily distinguish between smart contract and external addresses.
Warning: The checks in this library can be circumvented by calling from within a contract constructor. See the tests for a detailed attack example and check out this discussion exploring the issue.
Consider carefully whether this is acceptable in your use case.
Installation
- In your project run
npm install @1001-digital/check-address
- Within your contract, import the library
import "@1001-digital/check-address/contracts/CheckAddress.sol";
- In your code, you can check address types like so:
address account = 0x1234567891011121314151617181920212223242
if (CheckAddress.isExternal(account)) {
// ...
}
Note: You will have to link the library when creating your contract during development:
const CheckAddress = await ethers.getContractFactory('CheckAddress');
const library = await CheckAddress.deploy()
const MyContract = await ethers.getContractFactory('MyContract', {
libraries: {
CheckAddress: library.address,
},
});
Local Development
To set up your environment run npm install
.
Note: You can exchange npm run
for hh
if you have hh
installed globally on your system.
- Run the test suite:
npm run test
- Spin up a local development blockchain:
npm run node
- Deploy the contract with
npm run deploy:localhost
Deployment
Deploy the project via npm run deploy:{NETWORK}
with NETWORK
being one of localhost|rinkeby|ropsten|mainnet
.
Live Deployments
- Mainnet: TODO
- Ropsten:
0x87f11cba2Db0cB22b9679c14860bA5Be49Fd0717
- Rinkeby:
0x029374cA831F9F4B04a0D896B8d00CcE05f30D8f
Thank You
If you have any improvement suggestions, feedback or bug reports please feel free add an issue, or reach out via Twitter @jwahdatehagh or Email jalil@1001.digital.