- Public
- Opensource
- Introduce standards
- Same structure, libraries, and contracts
This tidbit is particularly interesting https://docs.openzeppelin.com/contracts/4.x/access-control
- Create a new project with
npm init
andtruffle init
commands - Add contracts to project with
npm install @openzeppelin/contracts
- You should now have
node_modules
directory under your token project - Import the openzeppelin contracts you want to use
- run
truffle develop
,compile
,migrate
*migrate --reset
if you've run it before already - let instance = await Token.deployed()
- Interact via console e.g
instance.symbol()
,instance.balanceOf(accounts[0])
BN = Big Number
How to conver it to something human readable
let result = await instance.balanceOf(accounts[0])
result.toNumber()
result.toString()
Prevent a function from being entered again if it's already running by the same process.
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
then you can just use that function like a modifier after importing it.
Make sure the address is a contract or a wallet
Full list here
- Ownable
- Roles
- SafeMath
- SafeCast
- ERC20Detailed
- ERC721Enumerable & ERC721Full
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/contracts/drafts/Counters.sol";
contract GameItem is ERC721Full {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
constructor() ERC721Full("GameItem", "ITM") public {
}
function awardItem(address player, string memory tokenURI) public returns (uint256) {
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
- Address (check if contract)