Skip to content

Commit

Permalink
update NFTEE2.sol constructor, add NFTEE_BASE_URI to .env
Browse files Browse the repository at this point in the history
- replace verifyingAddress with baseUrl
- in verifySignature, verifyingAddress is replaced by recipient
  • Loading branch information
zeroXbrock committed May 3, 2024
1 parent 6437f46 commit e7e80cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export L1_PRIVKEY=
export L1_RPC=
export BUILDER_URL=
export OPENAI_KEY=
export NFTEE_BASE_URI=
14 changes: 6 additions & 8 deletions examples/chatGPT-nft-minter/ethL1/NFTEE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {LibString} from "solmate/utils/LibString.sol";
contract SuaveNFT is ERC721 {
using LibString for uint256;

string private constant BASE_URI = "http://localhost:8080/metadata/";
// string private constant BASE_URI = "http://localhost:8080/metadata/";
string private baseUri;

// Event declarations
event NFTMintedEvent(address indexed recipient, uint256 indexed tokenId);
Expand All @@ -22,18 +23,15 @@ contract SuaveNFT is ERC721 {
// keccak256("Mint(string name,string symbol,uint256 tokenId,address recipient)");
bytes32 public constant MINT_TYPEHASH = 0x686aa0ee2a8dd75ace6f66b3a5e79d3dfd8e25e05a5e494bb85e72214ab37880;

// Authorized signer's address
address public authorizedSigner;

// token data
mapping(uint256 => string) public tokenData;

// NFT Details
string public constant NAME = "SUAVE_NFT2";
string public constant SYMBOL = "NFTEE";

constructor(address _authorizedSigner) ERC721(NAME, SYMBOL) {
authorizedSigner = _authorizedSigner;
constructor(string memory _baseUri) ERC721(NAME, SYMBOL) {
baseUri = _baseUri;
}

// Mint NFT with a signed EIP-712 message
Expand Down Expand Up @@ -80,7 +78,7 @@ contract SuaveNFT is ERC721 {
);

address recovered = ecrecover(digestHash, v, r, s);
return recovered == authorizedSigner;
return recovered == recipient;
}

function _exists(uint256 tokenId) internal view returns (bool) {
Expand All @@ -91,6 +89,6 @@ contract SuaveNFT is ERC721 {
/// but we're just using it to hold string data for NFTs.
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
return string(abi.encodePacked(BASE_URI, tokenId.toString()));
return string(abi.encodePacked(baseUri, tokenId.toString()));
}
}
6 changes: 3 additions & 3 deletions examples/chatGPT-nft-minter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func parseNFTLogs(chatNft *framework.Contract, receipt *types.Receipt) (*QueryRe
return queryResult, nftCreated
}

func deployEthNFTEE(ethClient *ethclient.Client, signerAddr common.Address, auth *bind.TransactOpts) (common.Address, common.Hash, *framework.Artifact) {
func deployEthNFTEE(ethClient *ethclient.Client, signerAddr common.Address, auth *bind.TransactOpts, baseURI string) (common.Address, common.Hash, *framework.Artifact) {
artifact, err := framework.ReadArtifact("NFTEE2.sol/SuaveNFT.json")
if err != nil {
panic(err)
}

// Deploy contract with signer address as a constructor argument
_, tx, _, err := bind.DeployContract(auth, *artifact.Abi, artifact.Code, ethClient, signerAddr)
_, tx, _, err := bind.DeployContract(auth, *artifact.Abi, artifact.Code, ethClient, baseURI)
if err != nil {
log.Fatalf("Failed to deploy new contract: %v", err)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func main() {
log.Printf("ChatNFT deployed on SUAVE (address=%s)", chatNft.Raw().Address())

// Deploy Ethereum L1 Contract
nfteeAddress, nfteeTxHash, nfteeArtifact := deployEthNFTEE(ethClient, privKey.Address(), auth)
nfteeAddress, nfteeTxHash, nfteeArtifact := deployEthNFTEE(ethClient, privKey.Address(), auth, cfg.NfteeBaseURI)
log.Printf("NFTEE deployed on L1 (%s): %s\n", nfteeTxHash.Hex(), nfteeAddress.Hex())

// Create NFT on SUAVE (sign a message to approve a mint on L1)
Expand Down
3 changes: 3 additions & 0 deletions framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ type Config struct {

// OpenAI API key
OpenAIKey string `env:"OPENAI_KEY"`

NfteeBaseURI string `env:"NFTEE_BASE_URI, default=http://localhost:8080/metadata/"`
// TODO: change this =============================>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ to a public IPFS node
}

type ConfigOption func(c *Config)
Expand Down

0 comments on commit e7e80cb

Please sign in to comment.