SECRET OF CSS

How to integrate NFT smart contracts with OpenSea


Ways to work with listed on OpenSea smart contract collection

1*OncEm WIU4VLrOSBgyA4sA

I was working in Custom App on several blockchain projects for 4 years.

We are currently developing a W3dding iOS web3 application and faced some issues while integrating our SBT (SoulBounded Token) ERC1155 smart contract with OpenSea. In this article we will discuss these issues and ways to solve them.

So, you got your NFT ERC721/ERC1155 smart contract listed on OpenSea (or you are planning it). You’ll see something like this after getting listed:

1*CNdaJEpB6nw044GhCg151Q
Default OpenSea listed smart contract collection view.

If you want to know how to edit any property of the collection, this article is for you. We are going to discuss, which account will own the listed smart contract collection by default and some OpenSea features to manage integrated collections.

For a better understanding you should be familiar with Solidity, OpenSea, ERC721/ERC1155 and some deployment/testing frameworks (Truffle, Hardhat etc.). All code from the examples can be found in our GitHub repository.

By default, the account, that deployed the smart contract to the live network, will be the owner of your collection, so all you need to do is to connect your wallet with this account to OpenSea. Then you’ll see your collection in “My Collections” tab, and you’ll be able to edit it!

To see that, let’s deploy a simple NFT smart contract into Polygon testnet (Mumbai) and check it in OpenSea. We are going to use account with address 0x64FC7AD6aEC6101B362600E463C77F50d8a1b881 to deploy contract, mint single NFT to account 0x7F886b3649231654A4E3b41124B296d8fcd68676 with metadata URI ipfs://bafkreiglpboznxavcx3edrgqfbtecanntlhenixusoghdtng5npyn4w4xe. We need to mint one NFT, since OpenSea doesn’t allow listing of empty collections.

Simple NFT smart contract

Deployed contract: 0x70e292d2745EF87E9e030f594e048f64839f175e. Now let’s connect wallet with deployer account and check listed collection.

1*jThWnlRK8IP4Dl5CS279fA
OpenSea collection view with a connected wallet with the deployer account.

After we connected the wallet with the deployer account, the “Edit” button appears, so now we can change any property of the collection.

So, using a deployer account is the quickest way to get edit access to your OpenSea collection. Also, this is the only possible option to get access if you’ve already deployed your contract to the live network, and it isn’t upgradable, as all options we are going to discuss below require smart contract modification.

If you only need to change the name, description, and image of the collection, it is enough to implement a contractURI function in your contract:

NFT smart contract with contractURI implemented.

URL returning by thecontractURIfunction must point to JSON of the following format:

Contract metadata format.

Let’s try it and deploy our contract! We’ve uploaded the contract metadata example file into IPFS: ipfs://bafkreig45twl5mtmpwpdo3vteffjb33dwawhfmgigbk7upihuddcaxuhle to use it in our contract.

Deployed contract: 0xa8e9aDAaE25A0d247B7597DEB9Dc6Ba786aa61c8

1*tARgmhvbP3y8siuWm RADw
OpenSea collection created with a contract with contractURI implemented.

As you can see, by implementing this pattern, your collection will get listed on OpenSea with proper parameters. This solution is going to suit you if you want your smart contract listed on OpenSea with programmatically configured parameters — especially if you have many smart contracts to get listed.

Giving permissions

As mentioned before, by default, the contract deployer account will get edit access to your collection. But also, you can grant access to any account by using OpenZeppelin’s Ownable contract. All you need is to make your NFT contract inherit the Ownable contract and assign the ownership in the constructor.

Ownable NFT smart contract.

Let’s try it out. We are going to deploy NftForOpenSeaOwnable contract with _owner equals to 0xfe4D28350E00049542d026ecC46746dD05034252.

Deployed contract: 0xC6B7240D5ccAa4d117da62D11b4FF5c9885DD72F

1* 8RR3RHddXvOSqdd9znXVA
“Edit” page of the collection created with Ownable smart contract.

Now we can see, that collection has two collaborators — deployer and owneraccount.

An important detail here is that owner account collection ownership cannot be removed from OpenSea “Edit” page:

1*zJfjemByjnsyloJugqdUJA
“Edit” page viewed by deployer account.

As you can see, neither the deployer nor owner himself cannot remove an owner account from the list of collaborators.

Transferring permissions

If you want to transfer permission, you can do it with transferOwnership function. To test this, we are going to transfer permissions to account 0xE19058b26CFf34AFf232B5379D0Ff995d4F0796A. Transfer ownership transaction id: aa5472a948f66571ea58ab4c556fc34cce9ec54b2ea852015a981c220cf2ed8e

1*rcW6ucKQtKY0u3tlAgTikA
“Edit” page after ownership transfer.

Now the old owner account was changed by the new owner account.

So, the main advantages of using Ownable are:

  • The flexibility you gained on ownership management.
  • You don’t have to expose deployer account secrets to any wallet.
  • owner cannot be removed from collaborators accidentally or on purpose.

Bonus: Hint on separating access control to collection and smart contract

If you’re already using the Ownable, and you want to separate the contract owner account and OpenSea collection owner account, you can mix the Ownable and the AccessControl contracts. You can use the Ownable for OpenSea access management and the AccessControl for contract-level access control.

Mixing the AccessControl and the Ownable contracts.

So, you have three ways to manage your listed smart contract collection in OpenSea:

  • Use an account that deployed the contract — the quickest way to the ability to edit your collection. Also, this is the only way if you already deployed your contract.
  • Implement contractURIfunction — way, which will suit you, if you need to assign basic collection properties programmatically.
  • Use the Ownable contract — the most flexible and secure way to manage the collection edit access, but also the hardest to implement.

All contracts code from this article can be found in our GitHub repository.

Use the solution that suits you best, always check everything in testnet before deploying to mainnet and enjoy Web3 — this is the Way:)





News Credit

%d bloggers like this: