Expected working: I have a form where in I take nft details from admin user like nft image and other details. And after entering the details, user can save it on ipfs and also mint it with multiple quantities on opensea.
Issues facing: I am not getting a fixed or standard ipfs link every time I try to store nft on ipfs.
A new hash link is created, which is not managble in erc1155 mint function.
Below I have mentioned nodejs code, wherein I am passing details of nft to store on IPFS and then calling ERC1155 smart contract function to mint the same.
I have also mentioned my erc1155 mint function.
So is there any way to handle this either in smart contract or in moralis ipfs?
Nodejs Code:
var metadata_ipfs_url='';
ipfsArray.push({
path: `images/${imageid}.png`,
content: image
})
var raw = JSON.stringify(ipfsArray);
await axios.post("https://deep-index.moralis.io/api/v2/ipfs/uploadFolder",
raw,
{
headers: {
"X-API-KEY": 'API-Key',
"Content-Type": "application/json",
"accept": "application/json"
}
}
).then( (res) => {
img_ipfs_url=res.data[0].path;
}).catch ( (error) => {
console.log("err:",error)
})
let metadata = {
name: req.body.name,
description: req.body.description,
image: img_ipfs_url,
attributes:[{"trait_type":"occupation","value":req.body.occupation},
{"trait_type":"nationality","value":req.body.nationality},
{"trait_type":"rarity","value":req.body.rarity},
{"trait_type":"birthday","value":req.body.birthday},
{"trait_type":"tagfield","value":req.body.category}
}
let ipfsMetadatArray = [];
ipfsMetadatArray.push({
path: `metadata/${imageid}.json`,
content: metadata
})
var raw1 = JSON.stringify(ipfsMetadatArray);
await axios.post("https://deep-index.moralis.io/api/v2/ipfs/uploadFolder",
raw1,
{
headers: {
"X-API-KEY": 'API-Key',
"Content-Type": "application/json",
"accept": "application/json"
}
}
).then( (res) => {
metadata_ipfs_url=res.data[0].path;
})
.catch ( (error) => {
console.log("err:",error)
})
const accounts = await web3.eth.accounts.privateKeyToAccount('0x' + PRIVATE_KEY);
const contract = new web3.eth.Contract(contractABI1155, contractAddress1155);
const nonce = await web3.eth.getTransactionCount(accounts.address, 'latest'); //get latest nonce
const tx = {
'from': accounts.address,
'to': contractAddress1155,
'nonce': nonce,
'gas': 300000,
'data': contract.methods.mintToken(accounts.address,imageid,1).encodeABI()
};
ERC1155 solidity code:
constructor(address _token) ERC1155("https://ipfs.moralis.io:2053/ipfs/Qmdvs9VFjFXEv47gsSEgTR2tELFPwwex75GJCxV4Qcxpgf/metadata/{id}.json") {
own = msg.sender;
token = IERC20(_token);
}
function mintToken(address owner,uint256 tokenID, uint256 amount) public onlyOwner{
_mint(owner, tokenID, amount, "");
}
function uri(uint256 _tokenId) override public pure returns (string memory){
return string( abi.encodePacked("https://ipfs.moralis.io:2053/ipfs/Qmdvs9VFjFXEv47gsSEgTR2tELFPwwex75GJCxV4Qcxpgf/metadata/", Strings.toString(_tokenId),".json"
)
);
}
Reference Link:
Server Url:
https://1uvyaez8woy5.usemoralis.com:2053/server