zkBridge
Search
K

Cross-chain ERC-1155

Deploying the ERC1155 NFT Contract on the Sender Chain

Below is an example of a standard ERC1155 contract. You can use the Remix - Ethereum IDE to deploy this contract on an EVM-compatible blockchain.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract SimpleErc1155 is ERC1155URIStorage, Ownable {
constructor(string memory baseUri) ERC1155(baseUri) {}
function mint(address to, uint256 tokenId, uint256 amount) external {
_mint(to, tokenId, amount, "");
}
function setURI(uint256 tokenId, string calldata tokenURI) external onlyOwner {
_setURI(tokenId, tokenURI);
}
}
Once the contract is deployed, you can mint an NFT and conduct a cross-chain transfer via the zkBridge official website. If this is the first time you are transferring this NFT, zkBridge will automatically create a mapping contract on the receiver chain. If you wish to deploy the mapping contract for the NFT on the receiver chain by yourself, please refer to the tutorial below.

Deploying the Mapping Contract on the Receiver Chain

For ERC1155, you need to implement the IZKBridgeErc1155 interface and grant minting and burning permissions to the NFT bridge contract on the receiver chain.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
interface IZKBridgeErc1155 {
function zkBridgeMint(address _to, uint256 _id, uint256 _amount, string calldata _uri) external;
function zkBridgeBurn(address _from, uint256 _id, uint256 _amount) external;
}
contract ONFT1155 is IZKBridgeErc1155, ERC1155URIStorage, Ownable {
address public bridge;
modifier onlyBridge() {
require(msg.sender == bridge, "caller is not the bridge");
_;
}
constructor(address _bridge, string memory _baseUri) ERC1155(_baseUri) {
bridge = _bridge;
}
function zkBridgeMint(address _to, uint256 _id, uint256 _amount, string calldata _uri) external onlyBridge {
_mint(_to, _id, _amount, "");
// can cover uri
// _setURI(_id, _uri);
}
function zkBridgeBurn(address _from, uint256 _id, uint256 _amount) external onlyBridge {
_burn(_from, _id, _amount);
}
function setURI(uint256 tokenId, string calldata tokenURI) external onlyOwner {
_setURI(tokenId, tokenURI);
}
}
After deploying the contract on the receiver chain, please notify us and provide both the sender chain's and receiver chain's contract addresses, so we can add the mapping relationship for you.
To get in touch, you may either:
  1. 1.
    Send an email to [email protected]
  2. 2.
    Reach out to our community moderators on our Discord Server

Example:

Last modified 6mo ago