Skip to Content
Mastering Blockchain Programming with Solidity
book

Mastering Blockchain Programming with Solidity

by Jitendra Chittoda
August 2019
Intermediate to advanced
486 pages
13h 52m
English
Packt Publishing
Content preview from Mastering Blockchain Programming with Solidity

The _mint internal function

The _mint() internal function is used to mint a new NFT at the given address. As the function is internal, it can only be used from inherited contracts to mint new tokens.

This function takes the following arguments:

  • to: The address of the owner for whom the new NFT is minted
  • tokenId: The new tokenId for the token that will be minted

Let's look at the _mint() function code:

function _mint(address to, uint256 tokenId) internal {    require(to != address(0));    require(!_exists(tokenId));    _tokenOwner[tokenId] = to;    _ownedTokensCount[to] = _ownedTokensCount[to].add(1);    emit Transfer(address(0), to, tokenId);}

As you can see in the preceding code, the new tokenId is checked using the _exists() function, which ensures ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ethereum

Mastering Ethereum

Andreas M. Antonopoulos, Gavin Wood
Complete Cryptocurrency and Blockchain Course | Learn Solidity

Complete Cryptocurrency and Blockchain Course | Learn Solidity

Ravinder Deol, Codestars By Rob Percival, Thomas Wiesner

Publisher Resources

ISBN: 9781839218262Supplemental Content