> For the complete documentation index, see [llms.txt](https://yuga.gitbook.io/zkyuga-whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yuga.gitbook.io/zkyuga-whitepaper/developer-guide/erc721/safemint.md).

# safeMint

The `safeMint` method is an integral feature of the ERC-721 token standard, designed for managing non-fungible tokens (NFTs) on the Ethereum blockchain. It facilitates the creation and assignment of a new NFT to a specified Ethereum address. The term "safe" in `safeMint` emphasizes the method's capability to ensure that the recipient address can safely handle NFTs, thereby guarding against potential vulnerabilities.

This method is encapsulated within the `ERC721Instance` object, accessible via appropriate client library functions, such as `ZkyugaClient`.

### Method Signature

```javascript
async safeMint(recipient: string, tokenURI: string, signer: WalletSigner): Promise<TransactionResponse>
```

#### Parameters

<table><thead><tr><th width="132">Parameter</th><th width="131">Type</th><th>Description</th></tr></thead><tbody><tr><td>recipient</td><td>string</td><td>The Ethereum address designated to receive the newly minted non-fungible token (NFT).</td></tr><tr><td>tokenURI</td><td>string</td><td>A unique resource identifier string pointing to the metadata of the token, typically referencing a JSON file describing the properties and attributes of the NFT.</td></tr><tr><td>signer</td><td>WalletSigner</td><td>The signer instance responsible for initiating and signing the transaction. This can originate from various sources, such as software wallets, hardware wallets, or private key storage solutions.</td></tr></tbody></table>

#### Returns

* A `Promise` resolving to a `TransactionResponse` object, furnishing comprehensive details about the minting transaction, including its status, transaction hash, and more.

### Usage Example

Start by obtaining an instance of the desired ERC-721 token contract:

```javascript
const erc721 = zkyugaClient.getERC721Instance("your ERC-721 contract address here");
```

Then, utilize the `safeMint` method to create a new NFT securely:

```javascript
const recipientAddress = "0xExampleRecipientAddressHere";
const metadataURI = "https://example.com/token/1012.json"; // An example token metadata URI
const signer = zkyugaClient.createWalletSigner("your private key");

const transactionResponse = await erc721.safeMint(recipientAddress, metadataURI, signer);
console.log(`Minting Transaction Hash: ${transactionResponse.hash}`);
```

### Notes

* Verify that the minting address (associated with the signer) possesses the requisite permissions or roles to mint tokens, as specified in the ERC-721 contract.
* The `tokenURI` typically points to metadata regarding the NFT, such as its name, image, description, and other attributes. Ensure it is both accessible and correctly formatted.
* The `safeMint` method conducts a check to ascertain whether the recipient address can handle ERC-721 tokens. If not, the minting process is aborted to prevent tokens from being sent to contracts or addresses unable to manage them.

***
