-
Notifications
You must be signed in to change notification settings - Fork 394
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
Adding Polygon support #57
Conversation
Hi @Jonas-Lieske, thank you very much for this contribution, I'm gonna review this PR as soon as possible. Would you mind if I make some changes (if needed) or implement the missing stuff for the DAPP? And also, would you be willing to test the final result so we can make sure everything is fine before merging? Thank you. |
Do as many changes as needed 😁 |
Did you also do the things described in https://docs.opensea.io/docs/polygon-basic-integration ? |
@tab00 we don't agree with the first suggestion provided by OpenSea ("Overriding isApprovedForAll() to reduce trading friction"). The hard-coded approval of the OpenSea marketplace is something that we don't want to implement by default in our contracts since we see it as a bad-practice from a security point of view. That said, I need to do some research about the rest of the article. 😉 |
Yes, I had come across some discussion recently about the risks of that in https://gist.github.com/483eb43bc6ed30b14f01e01842e3339b#gistcomment-4073311 |
Hi @Jonas-Lieske it seems like I made a mistake while trying to rebase your fork on the latest version and now I have no access to your repository. Would you please apply the following patch as a new commit and push it to your branch? commit c0da904673c48a72bff04eed6cab38fadff13a85
Author: Marco Lipparini <[email protected]>
Date: Sat Mar 5 20:35:11 2022 +0100
Added Polygon support
diff --git a/smart-contract/hardhat.config.ts b/smart-contract/hardhat.config.ts
index 0007696..4b4fe0b 100644
--- a/smart-contract/hardhat.config.ts
+++ b/smart-contract/hardhat.config.ts
@@ -112,6 +112,10 @@ const config: HardhatUserConfig = {
// Ethereum
rinkeby: process.env.BLOCK_EXPLORER_API_KEY,
mainnet: process.env.BLOCK_EXPLORER_API_KEY,
+
+ // Polygon
+ polygon: process.env.BLOCK_EXPLORER_API_KEY,
+ polygonMumbai: process.env.BLOCK_EXPLORER_API_KEY,
},
},
};
diff --git a/smart-contract/lib/Networks.ts b/smart-contract/lib/Networks.ts
index 687a252..d217c12 100644
--- a/smart-contract/lib/Networks.ts
+++ b/smart-contract/lib/Networks.ts
@@ -3,7 +3,7 @@ import NetworkConfigInterface from './NetworkConfigInterface';
export const ethereumTestnet: NetworkConfigInterface = {
chainId: 4,
blockExplorer:{
- name: 'Etherscan',
+ name: 'Etherscan (Rinkeby)',
generateContractUrl: (contractAddress: string) => `https://rinkeby.etherscan.io/address/${contractAddress}`,
},
}
@@ -15,3 +15,19 @@ export const ethereumMainnet: NetworkConfigInterface = {
generateContractUrl: (contractAddress: string) => `https://etherscan.io/address/${contractAddress}`,
},
}
+
+export const polygonTestnet: NetworkConfigInterface = {
+ chainId: 80001,
+ blockExplorer:{
+ name: 'Polygonscan (Mumbai)',
+ generateContractUrl: (contractAddress: string) => `https://mumbai.polygonscan.com/address/${contractAddress}`,
+ },
+}
+
+export const polygonMainnet: NetworkConfigInterface = {
+ chainId: 137,
+ blockExplorer: {
+ name: 'Polygonscan',
+ generateContractUrl: (contractAddress: string) => `https://polygonscan.com/address/${contractAddress}`,
+ },
+} If you save it to a My changes in version
And referencing the Polygon networks here:
The env variables are now generic so there is no need to add new ones, you can simply use the default ones. Let me know if you can help me with this, thank you very much! 🙏 |
Hey @liarco, I've applied and pushed the changes you mentioned, ran the tests and also did some manual testing. |
Thank you very much @Jonas-Lieske, I really appreciate it. You are right I have to make it customizable as well. 😉 I see you also mentioned you had to use the "gasMultiplier for polygon chain", is this still relevant? Would you please elaborate on this so I can understand if we need to take it into consideration too? |
No problem @liarco, I gotta thank you for this awesome repo 😉 Interestingly enough, the problem I mentioned where the gasMultiplier was needed is not occurring anymore 🤔 When I tested my implementation, an error message told me that the gas fees were set too low to deploy the contract. |
I'm happy to hear this might be fixed. Infura (which is also used by MetaMask) had a lot of issue in the past days so I have seen many people complaining about failing transactions, wrong gas estimations, etc. I hope it was the culprit. I committed the support for custom token symbols, I also decided to append an explicit Now I think we should take care of the optimizations suggested by OpenSea. I need to understand the purpose of each of them and I would like to limit the changes to what is absolutely required. |
You guys are the best !! I just want to now if the code is ready to use for polygon, or i need to wait for another tutorial to start my smart contract , i been trying everything and I see you guys are so close to get this code ready |
Hi @Juan34-crypto, it's not ready for production but if you could test it and give us feedback that would be appreciated. You can clone the git repo from this PR or you can download it as a ZIP file. Then you should be able to follow my instructions from the previous message:
I still need to know if the project works as expected on OpenSea or if it requires some specific changes in order to support the Polygon chain correctly. Thank you. |
Yes, that could be the reason 🙂
I have tested it on OpenSea and didn't encounter any error.
From what I can see the meta transactions would be a nice addition, not only for Polygon but also for Ethereum. |
Thank you @Jonas-Lieske, I took a look at the docs from OpenSea and I found a reference to this at the bottom: https://docs.openzeppelin.com/learn/sending-gasless-transactions But there you find a warning at the top, saying:
To me it's not clear if this method can still be considered a best-practice or if we should avoid it... I'm gonna do some more research! 😉 |
Hello @Jonas-Lieske here was my issue on closed tread: #96 (comment) |
@nftkk I'm sorry to say this but this is not what I actually meant. Here we are working on the implementation for the new feature, it's not a help-desk for personal support. You are more than welcome to:
If you can do this, then I will much appreciate it, but in the issue you linked above you are using a wrong version so we cannot help you with that. |
@liarco |
Ok no problem, but please, since copying changes manually can lead to errors, I ask you to start from a clean copy of the new code and test it as a brand new project. You should then report what you are doing and what's happening. Thank you for your time. |
Hello, I used the link in your reply above that says "the new code" and downloaded that zip file (nft-erc721-collection-main). After successfully deploying on polygon, verifying the contract, yarn build the minting-dapp, deploying the minting-dapp on a static host and finally opening the whitelist, I am met with the an error on the minting-dapp page that says Error Unsupported Network. This occurs when i connect my metamask to polygon, which is where the contract was deployed and successfully verified on polyscan. The only step i can see causing this issue was when you add in your ContractAddress to CollectionConfig.js before verifying. I added the ContractAddress and set it as a string but i forgot to save the file before verifying the contract. do you think this miss-step could cause that issue? if i connect my metmask to rinkeby while on the minting-dapp, a get this "Could not find the contract, are you connected to the right chain?". just for more insight. thanks for everything!! |
Hi @granthughes1999, thank you for your detailed information. 🙏 You should tell the system that you are using polygon networks instead of the ethereum one. Let me know if it's clear enough! 😉 Thank you |
@Juan34-crypto please calm down. This is not something you should take this way. It took me months (after 23 years studying/working as a developer) in order to get here, you should take your time nobody can speed it up for you here. It's all up to you. Your error is a connection error, you should check your configuration, maybe start over and follow every step really carefully. This is also an unstable version of this software, you are not supposed to launch a real project with this, so I don't see any reason to rush. We need to get this done right, not fast. |
@liarco now i its a bit funny. i start my terminal an run whiteliste open by the .env with private keys. today it works perfect. i didnt change anything. maybe yesterday the blockhain was busy and the gas fees higher. it seems that infura cant handle this. now it is the clean code of @Jonas-Lieske by the way it works now on both ways. direct by .env and truffle. after that i rund the dev-server and connect a wallet wich was on white list and try to mint. i get the same error as before. so there was no faults on my code before. At this point it must have something to do with DAPP and the configuration. I wonder why a gas fee is pre-calculated at this point, but from here on out it has to run normally via meta mask. Or have I thought incorrectly about that? i did research a bit and red something about (it was eth, but in this case i think it doesnt matter): Maybe the reason is my minting price? i want to set 100 matic, so i set it too 100.0 . I'm a bit confused though. on opensea you select the polygon block chain, but i have not seen any projects that trade with matic, but always with wrapped eth via the polygon chain. so my price would be wrong, that would be 100 eth lol. So do you always have to specify eth? if so, you would have to revise the code again so that no matic is displayed as currency. EDIT: i see on the video now it is relevant if you sell on opeansea, but in our case we dont sell it on opensea, we sell it on our own minting page. so the setting should be finde. we just have an gas issue here. but still have the question how will opeansea show the floor price if we mint on matic? opeansea only support wrapped eth or other currency on polygon but not direct matic. this is very important for collection. it would be very bad if opensea will show a floor price of 0 because matic is not supported. here is a video https://www.youtube.com/watch?v=tDsllLMLKWM
|
update: just the one question is very interesting. how will opensea handle the floorprice if we sell on matic wich is not supported on opensea? |
You were not stupid at all. We try to make this stuff accessible to a lot of people, but it's not easy to understand how everything works and all the things that can go wrong. It takes time and a lot of trial and error. Take your time, you will improve with time, like all of us.
You should check this out on the test version of OpenSea. |
I have now run a full test on the Mumbai Network. There are 2 important points that are missing.
i think this is very important for an collection. of course the target is to sell out on minting dapp but is is very important to show up an floor price for it. how was that on eth chain? is there a floor price? how can i add the % rarrity of the properties? |
@nftkk would you mind sharing the links so we can check it out? The first point should have nothing to do with this project, it might be just a "cache" issue (many ethereum collections on mainnet show the same thing at the beginning). I have no clue about floor price and volume. |
I did some research. the floor price and the trading volume only get tracked if you list directly on opensea, without own smart contract. i think i will run it on this way. there are 2 ways:
i want to got the 1st way, this was more professional for me. how can i send an selected nft to the owner? i just know how to mint to owner on polycan but dont now how i can choose the number of the nft there. |
Thanks for Polygon support! I have an issue to verify a contract on the Mumbai Network getting an error: Error in plugin @nomiclabs/hardhat-etherscan: Missing or invalid ApiKey In .env file I added the API Key from polygon.io Thank you |
@nftkk you can specify the amount of NFTs to mint for an address, not the IDs. @goshaminsk You are supposed to use the API key from polygonscan. |
@goshaminsk did you also apply the changes mentioned here? |
When you use the mint function you just pass the amount of token you want to mint. This is true also if the minter is the owner. If you want to mint specific NFTs for the owner you should do it on contract deploy. Let's say you want to mint the first 100 tokens in the contract. You should add a mint function like the following:
You will need to call
|
Successfully verified contract on Etherscan @liarco Thank you for you help! |
Hi @liarco and @Jonas-Lieske Just wanted to let you know that I was able to deploy my contract successfully to the Polygon Mainnet using the updated contract! Thank you so, so much for making this possible!! |
I used this repo to deploy multiple versions of my smart contract on the Mumbai Testnet. I also imported them into Opensea with no issues. First time it took something like half an hour, but subsequent contracts deployed with the same owner address got imported automatically. Once ready I deployed it to the Polygon Mainet following the same procedure. Everything went fine and the smart contract is on the blockchain: https://polygonscan.com/address/0xD15c3c9306ccD6D7c575a730A8cCb29bF98dB755. However, here there is the issue. Opensea keeps giving me the following error when I try to import it: It's been more than 36 hours so far. Any idea on what I might have done wrong? The only thing that comes to my mind is that I did Hopefully some of you can give me an insight. EDIT: |
Hi @ecerroni, I know that OpenSea doesn't allow you to import collections where no token has been minted yet. Can this be the issue in your case? |
@liarco I've minted them all after contract deploy. Now totalSupply is equal to maxSupply. I guess that should be it 🤔 Here there is the contract https://polygonscan.com/address/0xD15c3c9306ccD6D7c575a730A8cCb29bF98dB755 I still hope it's all been about bad timing. Maybe I had no luck while deploying following Polygon’s network outage last week. Indeed they announced yesterday that they will implement a hard fork on Heimdall that I hope will somehow make my contract reemerge in front of OpenSea if that was actually the issue. If that will not happen in the next few days then I have no idea what happened. @Berenike29 @goshaminsk were you able to deploy on Polygon Mainet and import the contract on OpenSea or was it just on Testnets? |
Hi @ecerroni yes I was able to deploy on the Polygon mainnet! |
Thanks for chiming in. Were you also able to import the same contract on OpenSea and start selling items? |
@ecerroni are you sure that your tokens are not under the "hidden" tab on Opensea? Is this your profile? https://opensea.io/waucollections Because, since Polygon tokens are really cheap, OpenSea sets them as hidden by default in order to avoid showing promotional tokens on profile pages. Anyway I run some tests together with other devs and this PR seems finally ready to be merged. This feature will be included in the next release asap, I want to thank everyone for contributing (especially @Jonas-Lieske for the initial implementation and testing). |
Hi again, I have seemed to figure out my previous post and somehow had missed a comment from you regarding a couple changes in the the CollectionConfig.ts that you mentioned here: I made these changes, changing the ethereum labels to polygon on these lines, and the Dapp seems to be working fine now! Thanks once again for these posts and the help! |
Hello guys, first of all thank you very much for your works. I learnt so many things from you. |
Here is my solution on how to implement Polygon support as discussed in #21.
Requirements
The hardhat-etherscan package needs to be updated to version 3.0.0 since it offers a new feature to configure multiple API keys for scans at once. The doc entry is HERE. I haven't noticed any problems with the update.
Improvements that could be made
I do not have any experience with REACT so I didn't try to change anything on the code base. It still says ETH for the pricing and the polygon chain is not being recognized as a main chain.
I also needed to use the gasMultiplier for polygon chain since there have been problems with the deployment and verification, because of a too low gas fee. AFAIK this is a problem with the calculation of gas fee by hardhat.
I tested it and it worked, however I only recently got into the field of smart contracts so I would appreciate any feedback!