Skip to content

Commit

Permalink
add custom token uri for crucibles
Browse files Browse the repository at this point in the history
  • Loading branch information
itirabasso committed Mar 3, 2022
1 parent 7eff26a commit c07a322
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contracts/crucible/CrucibleFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.7.6;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

import {IFactory} from "../factory/IFactory.sol";
import {IInstanceRegistry} from "../factory/InstanceRegistry.sol";
Expand All @@ -13,10 +14,12 @@ import {IUniversalVault} from "./Crucible.sol";
/// @title CrucibleFactory
contract CrucibleFactory is Ownable, IFactory, IInstanceRegistry, ERC721 {
address private immutable _template;
using Strings for uint256;

constructor(address template) ERC721("Alchemist Crucible v1", "CRUCIBLE-V1") Ownable() {
require(template != address(0), "CrucibleFactory: invalid template");
_template = template;
_setBaseURI('https://crucible.alchemist.wtf/nft/');
}

/* registry functions */
Expand Down Expand Up @@ -83,4 +86,26 @@ contract CrucibleFactory is Ownable, IFactory, IInstanceRegistry, ERC721 {
function getTemplate() external view returns (address template) {
return _template;
}

/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");

string memory base = baseURI();

uint256 id;
assembly {
id := chainid()
}

// concatenate the tokenID and chain id to the baseURI
return string(abi.encodePacked(
base,
tokenId.toString(),
'?network=',
chainId.toString()
));
}
}

0 comments on commit c07a322

Please sign in to comment.