Iya paham bang, bukan pengkodean yg ana maksud, tp kl ada contoh kan paling tidak bisa memberi sedikit gambaran
OK om, saya jelaskan secara simplenya saja ya, sesuai yang om tanyakan di atas (ownable, mintable, burnable):
-
ownableUmumnya tiap token terdapat fungsi ownable, biasannya digunakan untuk me-renounce si pemilik token. Renounce = mengubah alamat pemilik ke null atau zero address, dengan maksud supanya token tersebut tidak dapat diubah nilai dari variabel yang terdapat di dalamnya, misalnya variabel fee (marketing fee, team fee, charity fee, dan sebagainya).
Kode fungsi ownable:
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
-
mintableToken jenis mintable biasanya tidak berdiri sendiri, maksudnya proyek token mintable mempunyai tambahan smart contract lain, seperti smart contract MasterChef, TimeLock, atau bahkan sampai bikin Router sendiri.
-
burnableBurnable hanya menambahkan fungsi untuk burning token, fungsi transfer biasa sih, transfer ke null/zero address atau dead address. Tinggal nanti kita menentukan kapan proses burn nya terjadi, apakah saat terjadi transaksi atau secara manual.
contoh kode fungsi burn
function buyBackAndBurn(uint256 amount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = uniswapV2Router.WETH();
path[1] = address(this);
uint256 initialBalance = balanceOf(marketingWallet);
// make the swap
uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}(
0, // accept any amount of Tokens
path,
marketingWallet, // Burn address
block.timestamp.add(300)
);
uint256 swappedBalance = balanceOf(marketingWallet).sub(initialBalance);
_burn(marketingWallet, swappedBalance);
emit SwapBNBForTokens(amount, path);
}