Intro to me. My first post
Hello, I have been learning Information Technology all my life (21 now), it's my profession. For the past 18 months, studying JS and Solidity has been ideal. Considering the position I was in, which was 2 years of messing with industries I had no interest in, programming has helped me hugely with my adult life. It has provided me meaning and something to structure my life with/around, and taught me to organise my life. I was confused after leaving college in 2018, finishing my course in IT, but having no clue of where I was going to be. As I was growing up, I was scared of anything more than simple, like programming. I was not curious to learn anything and would be anxious of what others thought of me when I succeeded/failed. Slowly, I came out of this hole. This required me to be more self-aware. I learn't my skills, starting in small baby steps (helloWorld.js, print to console and all that :D.) which is definitely the way to go. Patience was key. With experience in React.js and Express.js, as well as Solidity, I am aiming for a career as a full-stack blockchain app dev.
The OLD GitHub Repo
The New Hardhat repo with MetaTXs on Polygon
A New Hardhat repo with MetaTXs and ERC1155 support
Here you will learn the basics of deploying a simple ERC-721 contract to the Mumbai testnet and how it all works.
Feel free to skip through the guide, taking only what you need and moving on. However, this is not a 'do this, then do this' tutorial (or whatever the slang is for that). I want to explain what is going on in the code, creating some knowledge for you, albeit with basic tools. Prepare for this to get verbose.
This is inspired by the ERC-721 Opensea Tutorial, as well as the Openzeppelin ERC-721 Tutorial. I plan on building my own tutorial with additional detail, and smoother guidance. You could just delegate the deploying and minting to Opensea with their frontend, but this is a basic start for developers to build project ideas off of.
I have found that the following are great for delving into Solidity: CryptoDevHub for direction and Solidity By Example for code examples.
This project uses the Truffle dev framework, as it is easy to begin with, and will give you experience with a node.js environment. Hardhat is preferred in the community. However, my knowledge of hardhat isn't up to standard at this moment. For the scope of this tutorial, Truffle will do nicely, but a Hardhat tutorial is due in the future. If you have 0 knowledge in solidity, you can always check out Remix for a quicker, smaller dev tool in the browser to get pracitising the basics of solidity.
My next tutorial will be focused on ERC-1155, the improvement on ERC-721. This newer standard allows the developer to have multiple collections of fungible and non-fungible tokens in 1 contract, reducing gas.
Token Metadata Storage
I will be using Pinata for fast, simple uploads to IPFS. This is a third-party service. Although, In future, I would recommend grabbing IPFS for desktop so that you can run a node on a Raspberry pi or such. At the time of writing this, the performance of the IPFS network has been fluctuating. Hosting an IPFS node would be the super professional way, but out of the scope of this tutorial. You may be interested in an alternative like Arweave. Arweave is similar to IPFS in that its a distributed network. However, Arweave use a Blockweave approach, more similar to a chain. Basically, you can pay gas to store immutable files.
Let us go through some prerequisites that you will need, and links to learn more about the tools you will be using. Previous coding knowledge is a big bonus. I am using Windows 10 with default cmd, not ps, but MACos and most Linux distros should function the same for this tutorial.
Prerequisites
- Basic/intermediate knowledge of the Ethereum blockchain (from an app developer view)
- Basics of Solidity, the most popular language for ethereum contracts. This includes the trusted ERC interfaces for contracts to extend, provided by OpenZeppelin.
- Node JS installed on your OS. Intermediate knowledge of JavaScript, node.js in particular.
- Truffle CLI installed on your OS. Basics of Truffle dev tool
- Basics of IPFS
- VS Code or another text editor IDE like atom , sublime text or eclipse
- MetaMask browser extension, with Polygon Mumbai testnet configured. You can make a new wallet when installing it on another/new browser, to avoid using your main.
- Git CLI for cloning the repo.
- Create an account at Pinata for 1gb of metadata storage.
- Create an account at MaticVigil for a polygon (fka matic) node url. Easiest third-party polygon node.
Links
- Eth docs for devs
- Solidity
- OpenZeppelin's ERC-721 docs
- JS docs
- Node.js
- Truffle docs
- IPFS docs + Pinata
- VS code dl
- Metamask
- Configure matic networks on Metamask
- Git
If you dont have all of these, or none, I would start by installing Node and then the rest (Truffle framework uses node.js and requires node to install it). Once you have node, you can enter npm i -g truffle
in a fresh terminal.
Setup Environment
You could start entering git
into the console. Then, check node
as well. With that, boot VS Code, make a new workspace or folder. Open a new terminal in the folder and clone The Repo with git clone https://github.com/YourNewEmpire/Truffle-Tutorial-ERC721
. Once its cloned, enter npm install
to install all the modules we need for this project, rudimentary npm at work here.
Create the file '.env' in the roof the project. This file will hold your wallet seed phrase/mnemonic and free matic node url for your scripts. Write the following lines in the file
MNEMONIC=
NODE_KEY=
Wallet
To begin, lets configure metamask to connect with the mumbai testnet. Go here to find the network details of matic/mumbai. Select the Mumbai Testnet and copy name, chainid, any 1 of the rpc urls, MATIC as the currency. Type them into your metamask here
This can be cumbersome, as metamask will close when you interact with the site again. It can be easier to type them in manually.
Lets get your wallet seed phrase for the environment variables so we can send transactions. Click your avatar in the top right, then settings.
Scroll to find Security & Privacy. Then click the red Reveal Seed button, with your password ready.
Copy the seed phrase, paste it into your .env, MNEMONIC=private key here
. Now you can use this var in your deploying and minting scripts. They are already binded in the JS scripts using Template Literals
You will need your eth address for the web3 scripts when minting items to yourself. Copy your address from here
Go to truffle-tutorial\scripts\mint.js
in your project. Finally, paste your address into line 14 const OWNER_ADDRESS = "HERE with the string quotes"
.
Head over to Matic Faucet,
Matic/Mumbai node url.
Creating an account at MaticVigil will give you a dedicated rpc url key for smooth contract interactions.
Once logged in and on the Dashboard, you can Create a new app, this should appear straight away on your Dashboard.
Paste it into your .env NODE_URL=key
.
Ok. With your environment setup, let's move on to getting token metadata ready for when tokens are minted
Metadata format for Opensea
To begin here, let's look at minting NFTs at the contract level.
function mintItem(address player, string memory tokenURI)
public
onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
The mint function takes 2 arguments. The important one is the tokenURI. The mintItem function calls the _setTokenURI
function, which takes in the id (index), which was just assigned and the URI. The URI is just a link to the token resource. In our case, it's on IPFS.
The point here is that Opensea will be querying that tokenURI through the method tokenURI
, part of the ERC-721 standard interface.
You could also set a baseURI, as mentioned here in the OZ docs. This will be the prefix for token URIs, so that when you mint or query an NFT, you can just pass the id, and the prefix does the rest of the URI format.
So how does Opensea deal with a resource once it's got a URI to fetch? Here is where Opensea's Metadata Standards get introduced. Following these standards are required for Opensea to read and display your metadata, you do not want a blank image for an NFT.
Every token URI is gonna be a JSON file looking something like this:
{
"description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
"external_url": "https://openseacreatures.io/3",
"image": "https://storage.googleapis.com/opensea-prod.appspot.com/puffs/3.png",
"name": "Dave Starbelly",
"attributes": [ ... ],
}
Opensea is specifically looking for the names above, 'image', 'name' etc.
I will be using Name, Desc and Image. If you want to try audio and video, animation_url is the one as mentioned in the standards page I linked above. The image or animation url will point to another resource, also on IPFS. This is the image or video that will appear on Opensea
As well as NFT metadata, there is Collection metadata fetched from the contractUri()
function in the GameItem.sol contract. Each NFT contract is a Collection. Each minted token on the contract is an NFT. We will need to upload metadata for the Collection in the form of, image, name, desc.
Create and upload token metadata
Now that we know the guidance on NFT metadata, we shall write some up before deploying any contracts. Because of IPFS, I have decided to organise my folders, separating collection data from nft data. I follow this pattern because I usually mint more than 1 nft, therefore I want to upload my media in folders. Feel free to organise them in any way you want.
Start by creating 2 folders in the root of the project. collection-data and nft-data, you should consider adding this to gitignore if you ever push this to GitHub. Within collection-data, have your collection image and json file like so:
Of course, use your own values. The external_link is not crucial, but worth testing, and say if you leave name empty, Opensea will make a name.
As you may notice the image value is empty. We need to upload the collection image first, to get the image URI for the JSON file to point to, which we will upload next. Despite that they are together in a folder in the project, the image needs to be uploaded before the json.
Once you have your test collection image ready, open up Pinata IPFS from the prerequisites and upload it. After logging in, you will land straight at the uploading page. Click Upload a File and pick the collection image from your project in the file explorer.
In your dashboard, you will see the file has a CID or Content Identifier. As described in the IPFS docs, the CID is an address/hash based on the content, not a location. Not necessarily important for us but interesting nonetheless.
Clicking on the image will send you to a pinata gateway url. I have had my best experiences in using this URI format: https://ipfs.io/ipfs/your-collection-cid
. Copy this, and your CID from Pinata and paste it into the collection JSON in your project:
{
"name": "Collection Name",
"description": "A test collection for ERC721 tutorial",
"image":
"https://ipfs.io/ipfs/QmQ2CPtFwRxoASHmiqbTPSfuPr91NfbMw2fjPtgvz55LPL"
}
You can do the same for your nft-data. Upload the test nft image first, then copy and paste the cid into 'nft.json'. The JSON may look like this:
{
"name": "Example Coffee #1",
"description": "I am a coffee but, this .jpg extension allows me to be warm forever.",
"image": "https://ipfs.io/ipfs/QmSXSHaUDJTorFReSJA24HjruRo2yqYbxPUSbxG7xTi31c"
}
Finally, you can upload your JSON files for both collection, and nft[s]. When minting multiple NFTs, I like to upload all my media in one folder, so the uri will look like: https://ipfs.io/ipfs/folder-hash/nft1.jpg
. However, for this post I shall upload 1 jpg.
With that, we are done with the metadata. You will need the collection and NFT JSON CIDs for the next stage, when we will deploy and mint, ooh exciting.
Deploying and Minting the NFT
With the metadata and environment all set, we can begin this stage by viewing the GameItem.sol in the contracts folder of the project. It will look like this
pragma solidity ^0.8.0;
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";
contract GameItem is ERC721URIStorage, Ownable {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
// set contract name and ticker.
constructor() ERC721("Contract Name", "TIC") {}
//get the current supply of tokens
function totalSupply() public view returns (uint256) {
return _tokenIds.current();
}
// for opensea collection
function contractURI() public pure returns (string memory) {
return "https://ipfs.io/ipfs/your-collection-ipfshash";
}
function mintItem(address player, string memory tokenURI)
public
onlyOwner
returns (uint256)
{
_tokenIds.increment();
uint256 newItemId = _tokenIds.current();
_mint(player, newItemId);
_setTokenURI(newItemId, tokenURI);
return newItemId;
}
}
If you are new to Solidity, there is a bit to talk about here. Starting with pragma. Pragma simply sets the solidity compiler version to use when compiling the file. The project is using 0.8.0, the highest minor version of Solidity available, which can be set in the truffle-config.js.
We are then importing Ownable, for modifying function calls to owners only (you, the deployer), then Counters for the tokenId's, this is a trusted utility for keeping track of tokens safely. ERC721URIStorage inherits the classic ERC721 interface, and adds some token URI help to the contract, recently added in Openzeppelin version 4.x . You should definitely have a look at these libraries, and abstract contracts, as they are great examples for building your own interfaces.
The most important bit for us, is the contractURI function. As I was saying earlier, 1 ERC-721 contract is 1 collection. This function returns a string that is the URI to your collection JSON. Opensea will call this method when displaying your collection on their frontend.
Copy your collection JSON ipfs URI into the return statement.
function contractURI() public pure returns (string memory) {
return "https://ipfs.io/ipfs/your-collection-ipfshash";
}
Optionally, you may set the ticker and the token/contract name in the Constructor function. This function is ran once at deployment for initialising something. In our case, its inheriting ERC-721 through ERC721URIStorage, expecting ticker and name arguments. This a test, so I shall leave it default.
Providing your wallet phrase and node url are in the .env file, we can now deploy this contract. Open a new terminal in the project and enter truffle develop
. Powershell might need the npx
prefix. This command will prep the truffle cli for deploying, compiling and more. You could enter compile
for a single compile without having to deploy, but when you deploy, truffle will compile anyway.
To deploy run migrate --network mumbai
in the terminal. ** You may experience errors here**, especially with specific environments. These tools are certainly not perfect. A good troubleshoot would be to run migrate --network development to eliminate where the error is.
I got this:
Starting migrations...
======================
> Network name: 'mumbai'
> Network id: 80001
> Block gas limit: 20000000 (0x1312d00)
1_initial_migration.js
======================
Replacing 'Migrations'
----------------------
> transaction hash: 0x4f703c7184a36b92af5fdd5d7751a7ed444670031475dfc90009927b96949d82
> Blocks: 2 Seconds: 8
> contract address: 0xb6e5A1B174C1CA435cB43Cf61fF9064F87f5f0Ec
> block number: 18792256
> block timestamp: 1631363185
> account: 0x5f4c3843495Babe89cB3516cEbD8840024e741fa
> balance: 1.408520183748380055
> gas used: 245600 (0x3bf60)
> gas price: 3 gwei
> value sent: 0 ETH
> total cost: 0.0007368 ETH
Pausing for 2 confirmations...
------------------------------
> confirmation number: 2 (block: 18792258)
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.0007368 ETH
2_deploy_token.js
=================
Replacing 'GameItem'
--------------------
> transaction hash: 0x2a0bc70f5c77c9c28e4a237de7adf72bac55c5d05d744a013c1dbd67fd1f245b
> Blocks: 2 Seconds: 4
> contract address: 0x87E67eBEBb785060d4Ed85Bff7E67dEc9Efa87F4
> block number: 18792264
> block timestamp: 1631363201
> account: 0x5f4c3843495Babe89cB3516cEbD8840024e741fa
> balance: 1.400152706748380055
> gas used: 2743246 (0x29dbce)
> gas price: 3 gwei
> value sent: 0 ETH
> total cost: 0.008229738 ETH
Pausing for 2 confirmations...
------------------------------
> confirmation number: 2 (block: 18792266)
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.008229738 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0.008966538 ETH
- Blocks: 0 Seconds: 0
- Saving migration to chain.
- Blocks: 0 Seconds: 0
- Saving migration to chain.
Do not close the terminal, we are not done here. Above you can see that Truffle ran the Migration script, to deploy the Migrations.sol contract, which is follwed by the token script. This is truffle's way of deploying contracts. You could order more deployments by creating more js scripts in the migrations folder of the project. If you're deployment was successful, very well done to you, you have deployed your contract.
We need the token contract address for minting, and you could get this from the Mumbai Tesnet Block Explorer, under your address. Conveniently, the address was printed to the console by truffle after deployment to the blockchain.
Copy the contract address: your token address
line from the console under the 2_deploy_token.js log. Paste this into your scripts/mint.js file on line 13 like so:
const NFT_CONTRACT_ADDRESS = "0x87E67eBEBb785060d4Ed85Bff7E67dEc9Efa87F4"
The web3 script will need this constant variable for instantiating the contract, to call/send methods on it.
The script will also need YOUR account address in the OWNER_ADDRESS variable to mint to YOU, and for you to send this transaction.
You may notice that we are reading the contract artifact JSON with fs:
let rawdata = fs.readFileSync(path.resolve(__dirname, "../build/contracts/GameItem.json"));
let contractAbi = JSON.parse(rawdata);
const NFT_ABI = contractAbi.abi
This might need to be reworked for Linux and MACos. I am not super experienced with linux file systems. All the script is doing here is reading the contract ABI from another file in the project
Web3.js will need this JSON for reference when calling/sending. Therefore, if you compiled a completely different contract in the same project, you would overwrite the artifacts. Make a new project for new contracts after you're finished with this one
For the final requirement of this script, you need the CID hash of the NFT JSON you uploaded to Pinata IPFS earlier for the argument of the mintItem function. Paste it into your script here on line 43:
await nftContract.methods
.mintItem(OWNER_ADDRESS, `https://ipfs.io/ipfs/your-tokenjson-cid`)
.send({ from: OWNER_ADDRESS })
.then(console.log('minted'))
.catch(error => console.log(error));
With the script ready, run node scripts/mint.js
in the project terminal. You can open a new terminal to do this or press CTRL+C to exit the truffle cli in the current terminal.
Provided that there are no errors here, 'Minted' should be printed to console and you can check your account on the block explorer to ensure that it was minted. Post any errors in the comments and google them.
With your Metamask logged in on your browser, let's view our NFT on Opensea via an existing contract. Go to the Opensea Testnet frontend. Open the profile icon dropdown to sign in, then click My Collections:
Next, tap the 3 dots menu icon, next to Create a Collection, then 'import an existing contract'. You will then be asked whether the nft is on a mainnet, testnet. Select testnet of course.
Now you can pass your nft contract address into the field, and select 'Mumbai' in the dropdown on the left like so:
You may receive the following message: 'We couldn't find this contract. Please ensure that this is a valid ERC721 or ERC1155 contract deployed on Mumbai and that you have already minted items on the contract'.
This is a common issue, as Opensea will display your tokens when they can. As long as you can see the token contract and transactions on Polygon Scan, you know it is a valid ERC-721 contract and has minted 1 item. Some dev's have waited 24 hours + to get their NFTs to appear.
Here is my NFT. I made the mistake of not adding the collection hash to the contractURI function in my first attempt. Despite redeploying the contract with the fix, Opensea still cant read the collection metadata. Fortunately, you can change this by editing the collection. At least my 'Example Coffee' NFT metadata worked.
Final notes and Conclusion
With all the action behind us, let's have a review.
You have learnt a simple way of deploying ERC-721 tokens to the Polygon testnet, nice. You can repeat this process for Matic mainnet, providing you have MATIC tokens on your mainnet balance, and you edit your mint script to instantiate with the MATIC
keyword as oppose to MUMBAI
on line 31 of mint.js.
There are few extras that I missed for this tutorial.
Firstly, I could have verified the contracts for a more professional look. Although, it is easier to do this in Hardhat, despite the fact that I cannot get a working example with Hardhat yet. Truffle requires more configuration for verifying contracts, therefore I will leave this for the next tutorial.
Optionally, you can add extra code to your contract to avoid gas fees when selling items from Opensea. The Opensea documentation explains how to work it. Simply, you set Opensea's matic contract address as your operator for your contract. With this, Opensea can transfer NFTs for you, saving you, or any owner gas.
In addition to these extras, you might want to check out freezing your metadata in production. This is a feature by Opensea to stop mutable metadata. NFT buyers and sellers will be comforted to see that their metadata is frozen.
Finally, I would like to guide you towards bigger and better tutorials with these links:
- ERC-721 doc - The old standard we used
- ERC-1155 doc - The improved community standard for fungible AND non-fungibles
- Filip from Moralis on ERC-1155
Top comments (34)
Amazing post man! Incredibly helpful for someone new to blockchain development. One quick question:
If I'm deploying a whole folder of NFTs, can I put the metadata for each one in one JSON file? Or would they have to exist in separate JSON files?
Hi Jeremy. I would keep the JSONs as separate, as I know this way works for sure. Thanks.
I also would to like know this. Did you figure it out?
Thank you for this tutorial! Have you ever tried transferring tokens on the Matic network?
I'm having trouble using 'maticjs', and was wondering if you knew another option :)
github.com/maticnetwork/matic.js/d...
Hey Kane. This is a brief reply, as I am not at my PC right now. I would recommend using web3js or ethers, then calling the safeTransferFrom method on the erc 1155 contact. Thanks.
I tried using web3 but no luck. I scoured the internet looking for some sample code, but alas nothing :(
I don't know how to use web3 to select the contract (using the private key passed in from the command line). There's some ABI requirements apparently, but I have no idea how that works.
Ughhh.
I will follow you on here now. Then i shall dm you about what you are unsure about
Wow, really? You sir, are a gentleman and a scholar 😀
It's been so hard to find sample code for this.
Nice article!
Could we upload new NFTs to the existing collection?
Hello Hossein.
I have had a quick search in the IPFS forums and it looks like there are possible ways of doing this, but my knowledge with IPFS CLI is very little, albeit I used Pinata as third-party in this tutorial.
What I would do is override the virtual _baseURI() function from the inherited ERC-721 contracts, but importantly, have it return a variable. This variable would be have to be added to the NFT contract and should be mutated with a 'setBaseURI' function. Then, one would upload a new folder to IPFS with added content, and update the base URI with the new 'setBaseURI' function. With that, the mintItem function I wrote should be rewritten so that, you would not need to pass a URI string to every mint, and instead it just mints with the token ID. Then when you want token metadata from the inherited tokenURI function, it will conditionally check if there is a baseURI and if so, just return the baseURI concatenated with the ID.
I would recommend inspecting the ERC721URIStorage.sol and ERC721.sol files and all of the methods as I have done, and then finding a way around these kind of situations.
Have a look at this great article by Rounak Banik where this is actually implemented.
I hope I answered the question to a good standard.
I use ERC1155. So, I need to figure it out somehow.
And do you have the answer for my second question? "Is that possible to list them while we're uploading them?"
Thanks!
Oh sorry I missed that one. Have a look at Benm4nn's comments on this discussion. We were talking about the fact that OpenSea.js SDK does not support Polygon listings at this time. Which leads us to listing the items on OpenSea's front end. I have been looking around for a solution, still nothing other than listing old school. Best of luck finding a solution.
Hi again Hossein. The best solution for this listing problem would be writing a minter function and a constant variable for price of payable mint function.
And my second question is,
Is that possible to list them while we're uploading them?
can use infura for API key ?without using mumbai network.and also dont use pinata , by using IPFS directly .some not clear .you made collection json and nft json. and bith uplaod to pinata , and use only collection hash .right?also made two conflict . why collection json hash return in one place and why nft json hash in other place.
Great post Archie, creating the contract worked well, but when it came to minting I had problems. Not with your code but because I was trying to combine it with OpenSea's meta-transactions sample code, so the minting function could not longer be set to Ownable.
Please can you update your code sample to include Meta transactions too? It's making my head hurt trying to combine the two!
Thanks
Hello benm4nn. Thanks for the kind words. I have been planning on adding this. However, I was running into some issues, and couldn't finish it. For one, you will need to outdate the solidity compiler version, and all of your contracts down to 0.6.6 for use of the ContextMixin.sol from the @maticnetwork/pos-portal package, which is needed for the opensea tx's. I shall give it another go today, and I will get back to you. Thanks for the constructive talk.
Hey check out my new post. I was able to find the sample code from OpenSea.
Thanks for this great post. I've been trying to work through it, but the very last step of node scripts/mint.js fails. It says minted, then says 'gas required exceeds allowance (0)'.
I'm not sure where to set the gas allowance? it looks like there is no allowance set. I did set gas in the truffle-config.js
mumbai: {
provider: function () {
return new HDWalletProvider(MNEMONIC,
https://rpc-mumbai.maticvigil.com/v1/${API_KEY}
);},
network_id: 80001,
gas: 5000000,
gasPrice: 5000000000,
confirmations: 2,
skipDryRun: true,
},
but that did not seem to resolve. How do I set the gas allowance so I can mint the token? Thanks!
Hey. Have you tried running the script again? With gas and gas price on 'auto' string might work. Im not sure about this error message either unfortunately.
Hi archie, thanks for the tutorial, i keep on getting this error when i try to 'migrate --network mumbai' or 'matic', my .env is perfect and ive tried both seed phrase and private key. any advice? thanks.
Error: Unknown arguments format passed to new HDWalletProvider. Please check your configuration and try again
at Object.getOptions (C:\Users\zaina\OneDrive\Documents\CryptOud\Truffle-Tutorial-ERC721\node_modules\@truffle\hdwallet-provider\src\constructor\getOptions.ts:143:11)
at new HDWalletProvider (C:\Users\zaina\OneDrive\Documents\CryptOud\Truffle-Tutorial-ERC721\node_modules\@truffle\hdwallet-provider\src\index.ts:71:9)
at Object.provider (C:\Users\zaina\OneDrive\Documents\CryptOud\Truffle-Tutorial-ERC721\truffle-config.js:45:16)
at Object.getProvider (C:\Users\zaina\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\index.js:20:1)
at Object.create (C:\Users\zaina\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\index.js:13:1)
at TruffleConfig.get as provider
at Object.detect (C:\Users\zaina\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\environment\environment.js:19:1)
at Object.module.exports as run
at Command.run (C:\Users\zaina\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:189:1)
the migrate --network development shows this
Could not connect to your Ethereum client with the following parameters:
- host > localhost
- port > 7545
- network_id > *
Please check that your Ethereum client:
- is running
- is accepting RPC connections (i.e., "--rpc" or "--http" option is used in geth)
- is accessible over the network
- is properly configured in your Truffle configuration file (truffle-config.js)
Hey Hamza.
I can't really pin down what's wrong here. I would suggest double checking the steps in which you spin up truffle. Ensuring you have ran truffle develop, but then, I am sure you have done these steps. If you do find the solution to this, it would be great to learn more amongst us, here in the discussion. I feel my lack of knowledge has perhaps let you down here.
I have just updated the top of this post with the new repositories, which are now using Hardhat. I would suggest trying out the Hardhat repo instead, as Truffle and the HD wallet provider can be intermittent in specific environments. That's not to say Hardhat has its caveats too, but I have preferred the Hardhat suite in a new repo. I will not be removing the Truffle repo from my GH and you are more than welcome to keep hacking away.
Apologies for this late reply and I wish you the best in solving this issue or finding a work around.
Great post. Hoping you can update the code with the removal of gas fees on sales. I've tried but not sure if I've got it right.
Meanwhile I created the contract OK but getting the error when I try minting...
tried googling but found nothing at all on it...
TypeError: nftContract.methods.mintItem is not a function
at main (/Users/randb/Documents/GitHub/Polygon-NFT-ERC721/scripts/mint.js:44:8)
at Object. (/Users/randb/Documents/GitHub/Polygon-NFT-ERC721/scripts/mint.js:64:1)
Archie,
Thanks for the tutorial. Really helped in understanding some of the basics. Kind of stuck on meta-transaction piece to implement gasless transaction. Do you know where that can be implemented in this repo? Thanks for all of this.
What a blog boy. I really love it.
For the first time without any errors, I have created my contract. But my NFT image was not properly uploaded. It's about 3kb. Does the size matter?
And how can we integrate Polygon cotract with Opensea. I saw this tuttorial but not able to understand where to implement it properly.
docs.opensea.io/docs/polygon-basic...
Hi there. Glad to see your response. The size of your image should not matter, providing you dont break the 1gb pinata offers. Can you show me any kind of screenshot of this image issue?
In the next git repo commit, I am planning on using the code from here: github.com/ProjectOpenSea/meta-tra...
or fixing the code from the link you have there,
to integrate with Polygon, so that the contract can delegate Opensea to pay the gas fees for transfers of NFTs. I am not a solidity expert at this point in time, therefore I left this out of the blog post. I don't know if Opensea's tutorials are not reliable, or if I am not reliable, but I am working on this integration.
Hi Archie,
I am also having issue with NFT metadata. It's not uploading for NFT as well. I have followed everything from your blog but still getting this issue.
Here you can see the issue opensea.io/collection/mycont
I would be glad if you can help me with this.
Thanks.
Hey bro. Check that your NFT metadata and jsons are separate, and that the json points to the image with the image property. Could you link me something to see your code and metadata. Thanks