Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add collectibles contract #205

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions TestDappCollectibles.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import 'base64-sol/base64.sol';

contract TestDappCollectibles is ERC721 {

using Counters for Counters.Counter;
Counters.Counter private _tokenIds;

constructor() ERC721('TestDappCollectibles', 'TDC') {}

function mintCollectibles(uint numberOfTokens) public {
for(uint i = 1; i <= numberOfTokens; i++) {
_tokenIds.increment();
uint tokenId = _tokenIds.current();
_safeMint(_msgSender(), tokenId);
}
}

function tokenURI(uint tokenId) public pure override returns (string memory) {
string memory svg =
'<svg height="350" width="350" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">'
'<defs>'
'<path id="MyPath" fill="none" stroke="red" '
'd="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />'
'</defs>'
'<text>'
'<textPath href="#MyPath">'
'Quick brown fox jumps over the lazy dog.'
'</textPath>'
'</text>'
'</svg>';

string memory json = string(
abi.encodePacked(
'{"name": "Test Dapp Collectibles #',
Strings.toString(tokenId),
'", "description": "Test Dapp Collectibles for testing.", "image": "data:image/svg+xml;base64,',
Base64.encode(bytes(svg)),
'", "attributes": [{"trait_type": "Token Id", "value": "',
Strings.toString(tokenId),
'"}]}'
)
);

string memory uri = string(
abi.encodePacked(
"data:application/json;base64,", Base64.encode(bytes(json))
)
);

return uri;
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
"@metamask/eslint-config": "^6.0.0",
"@metamask/eslint-config-nodejs": "^6.0.0",
"@metamask/onboarding": "^1.0.0",
"@openzeppelin/contracts": "4.3.3",
"base64-sol": "1.1.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.0.2",
"eslint": "^7.29.0",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@
node-gyp "^7.1.0"
read-package-json-fast "^2.0.1"

"@openzeppelin/contracts@4.3.3":
version "4.3.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.3.3.tgz#ff6ee919fc2a1abaf72b22814bfb72ed129ec137"
integrity sha512-tDBopO1c98Yk7Cv/PZlHqrvtVjlgK5R4J6jxLwoO7qxK4xqOiZG+zSkIvGFpPZ0ikc3QOED3plgdqjgNTnBc7g==

"@types/anymatch@*":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@types/anymatch/-/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
Expand Down Expand Up @@ -1016,6 +1021,11 @@ base64-js@^1.0.2:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==

base64-sol@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/base64-sol/-/base64-sol-1.1.0.tgz#39c3c91a35790b6eb3b8e73114b46bacf0fc2865"
integrity sha512-mksLxtFyBcXd3LYK5UxyMj29YR//zoaeXpJaKRbnLQC0E99oCJl7VpKaJDXWAuTvnhxBU9XNYzhxSL8umsrxWg==

base@^0.11.1:
version "0.11.2"
resolved "https://registry.yarnpkg.com/base/-/base-0.11.2.tgz#7bde5ced145b6d551a90db87f83c558b4eb48a8f"
Expand Down