Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Viewing minted NFTS #196

Closed
silaslang opened this issue Apr 5, 2021 · 18 comments
Closed

Viewing minted NFTS #196

silaslang opened this issue Apr 5, 2021 · 18 comments

Comments

@silaslang
Copy link

Hi all, firstly thank you for all the hard work you put in on this. I have a question that I'm not sure if is appropriate for here but I cant find the answers anywhere else. Its not an issue with the software.

I minted an NFT on gochain network but I cant work out how to view it as an image. What wallet will show the image I linked to via ipfs pinning at pinata?

Thanks

@jmank88
Copy link
Contributor

jmank88 commented Apr 5, 2021

Hi @silaslang

Here is an example of an NFT with an image from our block explorer: https://explorer.gochain.io/token/0x29af464A1099Ddf11C5770d8E05CBa18cAeF47d4/asset/458574755479668142737315416416

You can try viewing any GoChain NFT asset by plugging in you own token contract address and asset ID:
https://explorer.gochain.io/token/<CONTRACT>/asset/<ID>

@silaslang
Copy link
Author

silaslang commented Apr 10, 2021 via email

@treeder
Copy link
Contributor

treeder commented Apr 10, 2021

Your token is here: https://explorer.gochain.io/token/0x7A5c15B8df397EF5aeDe2ef971f72838F663Ea51/asset/0

Which looks like your contract is returning a metadata URL here: https://i.ibb.co/bNDvqdM/Qm-ZQr6d-YSNXdr-Lt-CMzj-Avip-UFHT7-Qygs-W5k-AP1-XFuj-Y7-W1.png0

Which looks like a bad image URL, not a metadata URL.

You should read this so you understand how they work: https://eips.ethereum.org/EIPS/eip-721

@cmatomic
Copy link

cmatomic commented Apr 10, 2021

Look at this example: https://ipfs.io/ipfs/QmYP4SZMWLQ5ZcrkwTVK1v3NUK6fxvVDEHtTCyUAupg3jt
2º example:
web3 generate contract erc721 --symbol yourNFTsymbol --name "NFTNAME" --base-uri https://ipfs.io/ipfs/QmeP4vcyDQ9uzdRQNUcdfMgfvEGwbjixh2hSpkDNqBSHdZ?filename=nft.json

*do not change this part ?filename=

@treeder
Copy link
Contributor

treeder commented Apr 11, 2021

I don't think that's right either, the base-uri should be https://ipfs.io/ipfs/ (or "ipfs:https://" if you expect your users to have something that can understand ipfs:https://).

To use IPFS, it makes it quite a bit more complicated. You'll have to modify the contract web3 generates to use ERC721URIStorage and you can read more about why and how here. This should also have a new function like:

function mint(address owner, string memory metadataURI)
    public
    returns (uint256)
    {
        _tokenIds.increment();

        uint256 id = _tokenIds.current();
        _safeMint(owner, id);
        _setTokenURI(id, metadataURI);

        return id;
    }

Then to actually mint a token you have to do the following:

  • add image to ipfs and get image cid
  • create metadata json with name, description and image and in the image field, put: https://ipfs.io/ipfs/IMAGE_CID
  • add metadata json to ipfs and get metadata cid
  • Now you'd mint the token and pass in the cid

@cmatomic
Copy link

@treeder
web3 generate contract erc721 --symbol yourNFTsymbol --name "NFTNAME" --base-uri https://ipfs.io/ipfs/QmeP4vcyDQ9uzdRQNUcdfMgfvEGwbjixh2hSpkDNqBSHdZ?filename=nft.json
using this method obtained the following result .(the image may take a time to load )
https://explorer.gochain.io/token/0x411Cc12dA82389a6d170A25e42212d1854fa4E4d/asset/0

What did you mean by this "and pass in the cid" ?

@treeder
Copy link
Contributor

treeder commented Apr 12, 2021

To the mint function. You'd pass in https://ipfs.io/ipfs/{CID} for metadataURI.

Anyways, looks like you got it working. Want to share what you did? Your contract code?

@cmatomic
Copy link

cmatomic commented Apr 12, 2021

@treeder
I did not change anything in the contract code, I simply copied the link from the IPFS Desktop application, this after several attempts to mint an NFT.
But it is possible to use services such as pinata for that, just copy the CID and name of the .json file.
https://ipfs.io/ipfs/{CID}?filename=nft.json

@treeder
Copy link
Contributor

treeder commented Apr 12, 2021

@silaslang
Copy link
Author

silaslang commented Apr 12, 2021

Thanks everyone for all the input and help. It appears I am getting somewhat closer to grasping this. I am new to all this but I am enjoying the learning. I couldn't grasp https://ipfs.io/ so I created the .json and pinned it at pinata .

{

"name": "Never Liked This Banksy",

"description": "Silent Bill's streetart in reply to Banksys Never Liked The Beatles",
"image": "https://gateway.pinata.cloud
/ipfs/QmTqWkECDhFYL8mHXNkQvUjNzExouqMZLnpATaKMNYgEJV",

}

web3 generate contract erc721 --symbol SBFTW --name "Never Liked This Banksy" --base-uri https://gateway.pinata.cloud/ipfs/QmUxM3EZ7GdK6cxCyX8L8ajspnPCHJqn3FPnQAHYCZND9D?filename=banksy.json

The sample contract has been successfully written to SBFTW.sol file

web3 contract build SBFTW.sol

NAME: SBFTW
contractName: :EnumerableMap
contractName: :ERC165
contractName: :IERC721Enumerable
contractName: :SBFTW
contractName: :AccessControl
contractName: :Context
contractName: :ERC721
contractName: :ERC721PresetMinterPauserAutoId
contractName: :ERC721Burnable
contractName: :Counters
contractName: :Address
contractName: :Strings
contractName: :IERC165
contractName: :IERC721Metadata
contractName: :IERC721Receiver
contractName: :SafeMath
contractName: :EnumerableSet
contractName: :IERC721
contractName: :Pausable
contractName: :ERC721Pausable
Successfully compiled contracts and wrote the following files:
Source file SBFTW_flatten.sol
SBFTW.bin, SBFTW.abi

web3 contract deploy SBFTW.bin
Contract has been successfully deployed with transaction: 0xde3d02ff48be6d8eb1408dbe7fe816f891411522a2b3c5c654d70a59e79998a6
Contract address is: 0x933f5c97a357B7574a2763249A1157D70Fed8b3d

export WEB3_ADDRESS=0x933f5c97a357B7574a2763249A1157D70Fed8b3d

web3 contract call --wait --abi SBFTW.abi --gas-limit 2000000 --function mint 0x03f42d46a09b922FD3D98CaC46B5B52F7a3cB98C
Transaction hash: 0x42c8c7ef0fb21d923610a0d6791fd126baca8d00bd68857adb94033175963800
Waiting for receipt...
Transaction receipt address: 0x42c8c7ef0fb21d923610a0d6791fd126baca8d00bd68857adb94033175963800
Block: #18354374 0xf16395bc1ef07ef6711fd822b408e3db0024aa22476a43f9fb3c4be7aaee71f8
Tx Index: 0
Tx Hash: 0x42c8c7ef0fb21d923610a0d6791fd126baca8d00bd68857adb94033175963800
From: 0x56336272596E6dE04fD62D6A8a05821c0b0660F1
To: 0x933f5c97a357B7574a2763249A1157D70Fed8b3d
Gas Used: 158959
Cumulative Gas Used: 158959
Status: Successful
Post State: 0x
Bloom: 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000010000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000004000000000000000000000000000000000400000000000000102000000000000000080000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000000
Logs: [0xc000033970]
Parsed Logs: [
{
"name": "Transfer",
"fields": {
"from": "0x0000000000000000000000000000000000000000000000000000000000000000",
"to": "0x00000000000000000000000003f42d46a09b922fd3d98cac46b5b52f7a3cb98c",
"tokenId": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}
]

However, when viewed at Gochain Explorer I am getting this error:
JSON.parse: expected double-quoted property name at line 9 column 1 of the JSON data

I feel as if I am almost there , what do I need to fix? *

EDIT, its the comma isnt it in this

{

"name": "Never Liked This Banksy",

"description": "Silent Bill's streetart in reply to Banksys Never Liked The Beatles",
"image": "https://gateway.pinata.cloud
/ipfs/QmTqWkECDhFYL8mHXNkQvUjNzExouqMZLnpATaKMNYgEJV",

}

@treeder
Copy link
Contributor

treeder commented Apr 13, 2021

yes, it's the comma.

And again, you're doing it wrong. that base-uri won't allow you to have more than one NFT in your contract.

@silaslang
Copy link
Author

I'm so happy , I finally got it to work. Thank you for all the help. I appreciate your patience and assistance. It has been fun experimenting.

https://explorer.gochain.io/token/0x521e5CFc5bF50f46d61375cB466f2B8a89d204b2/asset/0

To mint more than 1 of these would do the following

web3 contract call --wait --abi BANSKY.abi --gas-limit 2000000 --function mint 0x03f42d46a09b922FD3D98CaC46B5B52F7a3cB98C (INSERT THE AMOUNT TO MINT HERE?)

@treeder
Copy link
Contributor

treeder commented Apr 13, 2021

no, you can only mint 1 at a time.

@ranjithSts
Copy link

hi @treeder your right need to update the contract mint function which is getting pulled using docker

@treeder
Copy link
Contributor

treeder commented Aug 30, 2022

@ranjithSts not sure what you mean, can you explain?

@ranjithSts
Copy link

I don't think that's right either, the base-uri should be https://ipfs.io/ipfs/ (or "ipfs:https://" if you expect your users to have something that can understand ipfs:https://).

To use IPFS, it makes it quite a bit more complicated. You'll have to modify the contract web3 generates to use ERC721URIStorage and you can read more about why and how here. This should also have a new function like:

function mint(address owner, string memory metadataURI)
    public
    returns (uint256)
    {
        _tokenIds.increment();

        uint256 id = _tokenIds.current();
        _safeMint(owner, id);
        _setTokenURI(id, metadataURI);

        return id;
    }

Then to actually mint a token you have to do the following:

  • add image to ipfs and get image cid
  • create metadata json with name, description and image and in the image field, put: https://ipfs.io/ipfs/IMAGE_CID
  • add metadata json to ipfs and get metadata cid
  • Now you'd mint the token and pass in the cid

i mean this should be the actuall format but in the web3 gentrate contract erc721 when this is called in mint function the metadatauri is not getting passed or there is no variable as tokenuri in mint function

@ranjithSts
Copy link

i think i have found a solution over here ... fix erc721 for latest openzeppelin changes (#182)

// This allows the minter to update the tokenURI after it's been minted.
// To disable this, delete this function.
function setTokenURI(uint256 tokenId, string memory tokenURI) public onlyMinter {
function setTokenURI(uint256 tokenId, string memory tokenURI) public {
    require(hasRole(MINTER_ROLE, _msgSender()), "web3 CLI: must have minter role to update tokenURI");
    _setTokenURI(tokenId, tokenURI);
}

}`

i just need to know how to call this function , is this should be correct .. need an example of this

web3 contract call --amount AMOUNT --address CONTRACT_ADDRESS --abi CONTRACT_ABI_FILE --function setTokenURI "tokenId" "tokenURI"

@treeder
Copy link
Contributor

treeder commented Sep 1, 2022

Looks right, you probably don't need the --amount flag though. Did you try it?

@gochain gochain locked and limited conversation to collaborators Sep 1, 2022
@treeder treeder converted this issue into discussion #271 Sep 1, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants