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.
- 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,
},
});
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
Deploy the project via npm run deploy:{NETWORK}
with NETWORK
being one of localhost|rinkeby|ropsten|mainnet
.
- Mainnet:
0x32336A625aacFA08fe9723d901FFf92A7E3465c1
- Ropsten:
0x87f11cba2Db0cB22b9679c14860bA5Be49Fd0717
- Rinkeby:
0x029374cA831F9F4B04a0D896B8d00CcE05f30D8f
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.