https://market.sandbox.immutable.com/inventory/assets/0xefe9ce25073e6cbb6deaa9c1b8dca8ade73b31b6/1
Introducci贸n al desarrollo en Capa 2
Desarrollando en capa 2
Introducci贸n al desarrollo en capa 2
Desarrollo en Optimistic Rollups
Obteniendo fondos en un tesnet de capa 2
Lanzando un token en Arbitrum
Frontend para DApps
Intercomunicaci贸n entre capas
Desarrollo en zkRollups
Lanzamiento de NFTs en Immutable X
Smart Contracts con Cairo en Starknet
Utilizando el SDK de zkSync 2.0
Desaf铆os t茅cnicos de los zkRollups
You don't have access to this class
Keep learning! Join and start boosting your career
Interacting with a zkRollup for a specific use will require us to know what use case it satisfies. Rely on its documentation and tools provided by its community and ecosystem to interact with this type of L2.
Immutable X is a specific use zkRollup that will not allow to mine NFT collections and trade with them. It is an ideal platform to launch web3 video games.
The first step is to register your wallet in this zkRollup. For this, we will use the Immutable X testnet to create an account.
When we say you will need "an account", we don't mean the traditional username and password. The project is decentralized, you will be able to create such an account by simply connecting your wallet to the platform. The platform will ask you for a series of signatures, free of charge, so that the smart contract will have access to your wallet and finalize the registration.
The ERC721 contract must be launched in L1 and it has to be specifically programmed to communicate with the Immutable X bridges and allow to mine the NFTs.
For this, we will launch the following contract in Goerli using Remix. It is a typical ERC721 contract with some important particularities to note.
The official Immutable X documentation specifies how our contract should be developed. It must import an interface called Mintable
that has all the ownership logic through OpenZeppelin and the mining of the NFTs.
```c import "@openzeppelin/contracts/access/Ownable.sol";
interface IMintable { function mintFor( address to, uint256 quantity, bytes calldata mintingBlob ) external; }
abstract contract Mintable is Ownable, IMintable { address public imx; mapping(uint256 => bytes) public blueprints;
event AssetMinted(address to, uint256 id, bytes blueprint); constructor(address _owner, address _imx) { imx = _imx; require(_owner != address(0), "Owner must not be empty"); transferOwnership(_owner); } modifier onlyOwnerOrIMX() { require(msg.sender == imx || msg.sender == owner(), "Function can only be called by owner or IMX"); _; } function mintFor(address user, uint256 quantity, bytes calldata mintingBlob) external override onlyOwnerOrIMX { require(quantity == 1, "Mintable: invalid quantity"); (uint256 id, bytes memory blueprint) = Minting.split(mintingBlob); _mintFor(user, id, blueprint); blueprints[id] = blueprint; emit AssetMinted(user, id, blueprint); } function _mintFor(address to, uint256 id, bytes memory blueprint) internal virtual;
} ```
That we could well import with import ``imtbl/imx-contracts/contracts/Mintable.sol``;
, making use of Immutable X's own contracts.
This interface, in turn, makes use of a library needed to manipulate the bytes of the NFT image.
```c library Bytes { function indexOf(bytes memory _base, string memory _value, uint256 _offset) internal pure returns (int256) { bytes memory _valueBytes = bytes(_value); assert(_valueBytes.length == 1); for (uint256 i = _offset; i < _base.length; i++) { if (_base[i] == _valueBytes[0]) { return int256(i); } } } return -1; }
function toUint(bytes memory b) internal pure returns (uint256) { uint256 result = 0; for (uint256 i = 0; i < b.length; i++) { uint256 val = uint256(uint256(uint8(b[i])); if (val >= 48 && val <= 57) { result = result * 10 + (val - 48); } else { revert("invalid input, only numbers allowed"); } } } return result; }
} ```
Finally, our contract. We implemented the ERC721 standard from OpenZeppelin, in addition to implementing also the Mintable
interface of Immutable X.
````c contract MyImmutableXCollectionDemo is ERC721, Mintable { constructor() ERC721("My IMX Collection Demo", "MIMXNFT") Mintable(msg.sender, 0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623) {}
function _mintFor(address user, uint256 id, bytes memory) internal override { _safeMint(user, id); }
} ```
The Immutable X interface receives as a parameter the address of the bridge in Goerli, in this case 0x7917...c623
.
It is common to call testing environments of any software as
Sandbox
. You may come across that name when inspecting the Immutable X ecosystem.
Deploy this contract using Remix, or your preferred web3 development environment, and we're ready to set up the client that will create your first NFT in Immutable X.
It is time to prepare the client that we will use to create NFTs in Immutable X. For this, you can use this repository as setup to have an environment ready to be configured and run the scripts that will interact with the contract and the second layer protocol.
We must configure a few environment variables in the project and perform a series of steps.
.env
file based on .env.examples
OWNER_ACCOUNT_PRIVATE_KEY
and COLLECTION_CONTRACT_ADDRESS
with your wallet's private key (you can export it from Metamask) and the address of the contract deployed in Step 2src/onboarding/2-create-project.ts
to set the variables name
, company_name
and contact_email
npm run onboarding:create-project
Note: remember to securely store your wallet's private key and not to share it with anyone.
COLLECTION_PROJECT_ID
in the .env
file with the ID given after executing the above commandname
, description
, icon_url
, metadata_api_url
, collection_image_url
in the file src/onboarding/3-create-collection.ts
npm run onboarding:create-collection
The NFTs in Immutable X are based on collections. The collection will have a name, a description, the URL to an icon, the metadata and an image of the collection itself. All these URLs are best obtained from decentralized services such as IPFS.
src/onboarding/4-add-metadata-schema.ts
, it can have a schema like the following:ts { name: 'name', type: MetadataTypes.Text }, { name: 'image_url', type: MetadataTypes.Text }, { name: 'description', type: MetadataTypes.Text }, { name: 'attack', type: MetadataTypes.Discrete, filterable: true }
The name, image and description must match the fields in the metadata of each NFT. Then you can add custom fields as attack
, this field must also exist in the metadata.
npm run onboarding:add-metadata-schema
.env
file, edit PRIVATE_KEY1
again with the private key of your wallet, TOKEN_ID
with the number of which NFT you want to mine from, and TOKEN_ADDRESS
with the address of the contract deployed in Step 2.wallet
and number
in the file src/bulk-mint.ts
with the public key of your wallet and the number of the NFT you want to mine fromnpm run bulk-mint
to mine your first NFT with Immutable XIf everything went well, go to the Immutable X Sandbox marketplace, login with your wallet and you should be able to see the newly created NFT.
This type of use-specific Rollups will allow you to launch large collections of NFTs. It may seem a bit confusing, you just need to pay attention to the logic of the contract and the correct configuration of the client with the relevant data you need.
Mastering these types of protocols can give you new skills as a blockchain developer to fulfill certain use cases in a job or simply to perform research on how the NFTs ecosystem is evolving.
Contributed by: Kevin Fiorentino.
Contributions 3
Questions 0
Immutable X me record贸 bastante a Metaplex y a como se pueden lanzar colecciones de NFT con Candy Machine en la blockchain de Solana. Aunque en Solana es algo m谩s sencillo, tiene menos pasos y configuraciones.
Want to see more contributions, questions and answers from the community?