Skip to content

Commit 6f1fee7

Browse files
authored
Add return tokenId (and adjust type) if incremental safeMint (#455)
1 parent 00fe635 commit 6f1fee7

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

packages/core/solidity/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
- Fix modifiers order to follow Solidity style guides. ([#450](https://github.com/OpenZeppelin/contracts-wizard/pull/450))
66

7+
## 0.5.2 (2025-02-21)
8+
9+
- ERC721 to return tokenId on safeMint with incremental id
10+
711
## 0.5.1 (2025-02-05)
812

913
- **Potentially breaking changes**:

packages/core/solidity/src/erc721.test.ts.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,15 @@ Generated by [AVA](https://avajs.dev).
184184
Ownable(initialOwner)␊
185185
{}␊
186186
187-
function safeMint(address to, string memory uri) public onlyOwner {␊
187+
function safeMint(address to, string memory uri)␊
188+
public␊
189+
onlyOwner␊
190+
returns (uint256)␊
191+
{␊
188192
uint256 tokenId = _nextTokenId++;␊
189193
_safeMint(to, tokenId);␊
190194
_setTokenURI(tokenId, uri);␊
195+
return tokenId;␊
191196
}␊
192197
193198
// The following functions are overrides required by Solidity.␊
@@ -404,9 +409,10 @@ Generated by [AVA](https://avajs.dev).
404409
Ownable(initialOwner)␊
405410
{}␊
406411
407-
function safeMint(address to) public onlyOwner {␊
412+
function safeMint(address to) public onlyOwner returns (uint256) {␊
408413
uint256 tokenId = _nextTokenId++;␊
409414
_safeMint(to, tokenId);␊
415+
return tokenId;␊
410416
}␊
411417
}␊
412418
`
29 Bytes
Binary file not shown.

packages/core/solidity/src/erc721.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Contract, ContractBuilder } from './contract';
1+
import { BaseFunction, Contract, ContractBuilder } from './contract';
22
import { Access, setAccessControl, requireAccessControl } from './set-access-control';
33
import { addPauseFunctions } from './add-pausable';
44
import { supportsInterface } from './common-functions';
@@ -185,14 +185,16 @@ function addMintable(c: ContractBuilder, access: Access, incremental = false, ur
185185
if (uriStorage) {
186186
c.addFunctionCode('_setTokenURI(tokenId, uri);', fn);
187187
}
188+
189+
if (incremental) c.addFunctionCode('return tokenId;', fn);
188190
}
189191

190192
function addVotes(c: ContractBuilder, name: string, clockMode: ClockMode) {
191193
const EIP712 = {
192194
name: 'EIP712',
193195
path: '@openzeppelin/contracts/utils/cryptography/EIP712.sol',
194196
};
195-
c.addParent(EIP712, [name, "1"]);
197+
c.addParent(EIP712, [name, '1']);
196198

197199
const ERC721Votes = {
198200
name: 'ERC721Votes',
@@ -219,9 +221,7 @@ const functions = defineFunctions({
219221

220222
tokenURI: {
221223
kind: 'public' as const,
222-
args: [
223-
{ name: 'tokenId', type: 'uint256' },
224-
],
224+
args: [{ name: 'tokenId', type: 'uint256' }],
225225
returns: ['string memory'],
226226
mutability: 'view' as const,
227227
},
@@ -242,13 +242,12 @@ const functions = defineFunctions({
242242
},
243243
});
244244

245-
function getMintFunction(incremental: boolean, uriStorage: boolean) {
246-
const fn = {
245+
function getMintFunction(incremental: boolean, uriStorage: boolean): BaseFunction {
246+
const fn: BaseFunction = {
247247
name: 'safeMint',
248248
kind: 'public' as const,
249-
args: [
250-
{ name: 'to', type: 'address' },
251-
],
249+
args: [{ name: 'to', type: 'address' }],
250+
returns: incremental ? ['uint256'] : undefined,
252251
};
253252

254253
if (!incremental) {

0 commit comments

Comments
 (0)