Skip to content

Customizing contracts - Mint Tokens on Deployment #7

@AddressXception

Description

@AddressXception

As a developer I would like to mint 100 tokens to a designated address when my contract is deployed so that the owner of the address can view the minted tokens in their wallet.

Our contract must mint 100 tokens to a specific wallet when it is deployed. Add an internal function that will call the _safeMint function found in the ERC721.sol base contract. The function should accept an address as a parameter. Call the function from the contract constructor.

Our contract will automatically mint 100 NFT's to a designated wallet when the contract is deployed. This is a common pattern for handling custom 1 of 1 artwork, or when allocating a portion of the tokens internally to the team, etc. Our contract will also allow up to 900 total tokens to be minted publicly but we will worry about that in the next section.

Since we want to mint our tokens on contract deployment, we require an internal function. Function visibility in solidity works similarly to other languages with one major caveat:

there's no such thing as private data on the blockchain.

since nodes on the network must be able to deterministically resolve a function, all private variables and access is simply not added to the public interfaces, but it is viewable on any node.

Check out this excellent post on access in solidity

For our function, we need to accept a single address as a parameter and create a simple loop that mints 100 tokens using the _safeMint function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions