Skip to content

Commit

Permalink
Change ERC721 samples to use auto-indexing mint by default
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
  • Loading branch information
awrichar committed Jan 9, 2023
1 parent 3c966fc commit 24aea22
Show file tree
Hide file tree
Showing 22 changed files with 956 additions and 435 deletions.
9 changes: 8 additions & 1 deletion samples/solidity/contracts/ERC721NoData.sol
Expand Up @@ -6,6 +6,7 @@ import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol';
import '@openzeppelin/contracts/utils/Context.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/Counters.sol';

/**
* Example ERC721 token with mint and burn.
Expand All @@ -18,9 +19,15 @@ import '@openzeppelin/contracts/access/Ownable.sol';
* This is a sample only and NOT a reference implementation.
*/
contract ERC721NoData is Context, Ownable, ERC721, ERC721Burnable {
using Counters for Counters.Counter;

Counters.Counter private _tokenIdCounter;

constructor(string memory name, string memory symbol) ERC721(name, symbol) {}

function safeMint(address to, uint256 tokenId) public onlyOwner {
function safeMint(address to) public onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
}

Expand Down
16 changes: 10 additions & 6 deletions samples/solidity/contracts/ERC721WithData.sol
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.0;
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/utils/Context.sol';
import '@openzeppelin/contracts/utils/Strings.sol';
import '@openzeppelin/contracts/utils/Counters.sol';
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import './IERC721WithData.sol';

Expand All @@ -24,7 +25,11 @@ import './IERC721WithData.sol';
* This is a sample only and NOT a reference implementation.
*/
contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
using Counters for Counters.Counter;

Counters.Counter private _tokenIdCounter;
string private _baseTokenURI;

// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;

Expand All @@ -44,21 +49,20 @@ contract ERC721WithData is Context, Ownable, ERC721, IERC721WithData {
super.supportsInterface(interfaceId);
}

function mintWithData(
address to,
uint256 tokenId,
bytes calldata data
) external override onlyOwner {
function mintWithData(address to, bytes calldata data) external override onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId, data);
_setTokenURI(tokenId, string(abi.encodePacked(_baseURI(), Strings.toString(tokenId))));
}

function mintWithURI(
address to,
uint256 tokenId,
bytes calldata data,
string memory tokenURI_
) external override onlyOwner {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId, data);

// If there is no tokenURI passed, concatenate the tokenID to the base URI
Expand Down
2 changes: 0 additions & 2 deletions samples/solidity/contracts/IERC721WithData.sol
Expand Up @@ -14,13 +14,11 @@ import '@openzeppelin/contracts/utils/introspection/IERC165.sol';
interface IERC721WithData is IERC165 {
function mintWithData(
address to,
uint256 tokenId,
bytes calldata data
) external;

function mintWithURI(
address to,
uint256 tokenId,
bytes calldata data,
string memory tokenURI_
) external;
Expand Down
179 changes: 81 additions & 98 deletions samples/solidity/test/ERC721NoData.ts

Large diffs are not rendered by default.

170 changes: 80 additions & 90 deletions samples/solidity/test/ERC721WithData.ts

Large diffs are not rendered by default.

File renamed without changes.
9 changes: 2 additions & 7 deletions src/abi/ERC721NoData.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 24aea22

Please sign in to comment.