- Install TON Solidity Compiler
- Install TVM linker
- Install nmp
- Create empty folder and move to it
- Init npm project.
npm init -y
- Install itgold library for development NFT.
npm i @itgold/everscale-tip
npm run test
- Create
Nft.sol
file and fill it.
pragma ton-solidity = 0.58.1;
pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;
import '@itgold/everscale-tip/contracts/TIP4_1/TIP4_1Nft.sol';
contract Nft is TIP4_1Nft {
constructor(
address owner,
address sendGasTo,
uint128 remainOnNft
) TIP4_1Nft(
owner,
sendGasTo,
remainOnNft
) public {}
}
- Create
Collection.sol
file and fill it.
pragma ton-solidity = 0.58.1;
pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;
import '@itgold/everscale-tip/contracts/TIP4_1/TIP4_1Collection.sol';
import '@itgold/everscale-tip/contracts/access/OwnableExternal.sol';
import './Nft.sol';
contract Collection is TIP4_1Collection, OwnableExternal {
/**
* Errors
**/
uint8 constant sender_is_not_owner = 100;
uint8 constant value_is_less_than_required = 101;
/// _remainOnNft - the number of crystals that will remain after the entire mint
/// process is completed on the Nft contract
uint128 _remainOnNft = 0.3 ton;
constructor(
TvmCell codeNft,
uint256 ownerPubkey
) OwnableExternal(
ownerPubkey
) TIP4_1Collection (
codeNft
) public {
tvm.accept();
}
function mintNft() external virtual {
require(msg.value > _remainOnNft + 0.1 ton, value_is_less_than_required);
tvm.rawReserve(0, 4);
uint256 id = uint256(_totalSupply);
_totalSupply++;
TvmCell codeNft = _buildNftCode(address(this));
TvmCell stateNft = _buildNftState(codeNft, id);
address nftAddr = new Nft{
stateInit: stateNft,
value: 0,
flag: 128
}(
msg.sender,
msg.sender,
_remainOnNft
);
emit NftCreated(
id,
nftAddr,
msg.sender,
msg.sender,
msg.sender
);
}
function setRemainOnNft(uint128 remainOnNft) external virtual {
require(TIP4_1Collection._isOwner(), sender_is_not_owner);
_remainOnNft = remainOnNft;
}
function _isOwner() internal override onlyOwner returns(bool){
return true;
}
function _buildNftState(
TvmCell code,
uint256 id
) internal virtual override pure returns (TvmCell) {
return tvm.buildStateInit({
contr: Nft,
varInit: {_id: id},
code: code
});
}
}
TIP: You can use another samples from everscale-tip-samples
- build
Nft.sol
file to use TON Solidity Compilersolc Nft.sol --include-path node_modules
- build
Collection.sol
file to use TON Solidity Compilersolc Collection.sol --include-path node_modules
- compile
Nft.code
file to use TVM linkertvm_linker compile --abi-json Nft.abi.json Nft.code --lib stdlib_sol.tvm -o Nft.tvc
- compile
Collection.code
file to use TVM linkertvm_linker compile --abi-json Collection.abi.json Collection.code --lib stdlib_sol.tvm -o Collection.tvc