GithubHelp home page GithubHelp logo

bedlam520 / opensea-migration Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lala-labs/opensea-migration

0.0 0.0 0.0 236 KB

A Solidity contract base to migrate OpenSea Shared Storefront tokens without asking for `setApprovalForAll`.

License: MIT License

JavaScript 21.80% Solidity 78.20%

opensea-migration's Introduction

opensea-migration

A Solidity contract base to migrate OpenSea Shared Storefront tokens without asking for setApprovalForAll.

Installation

Currently no packages are published on NPM. You can pull directly from git and the latest tag:

package.json

"opensea-migration": "git+https://github.com/lala-labs/opensea-migration.git#2.0.0",

Sample Migration Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "opensea-migration/contracts/OpenSeaMigration.sol";

interface NewContract {
  function mint(address to, uint256 tokenId) external;
}

contract MyMigration is OpenSeaMigration {
  NewContract public immutable NEW_CONTRACT;

  constructor(
    address newContractAddress, // your new contract to which the NFT should be migrated
    address openSeaStoreAddress, // mainnet:0x495f947276749Ce646f68AC8c248420045cb7b5e rinkeby:0x88b48f654c30e99bc2e4a1559b4dcf1ad93fa656
    address makerAddress // the address of the minter/creator of the original collection on OpenSea
  ) OpenSeaMigration(openSeaStoreAddress, makerAddress) {
    NEW_CONTRACT = NewContract(newContractAddress);
  }

  function _onMigrateLegacyToken(
    address owner,
    uint256 legacyTokenId,
    uint256 internalTokenId,
    uint256 amount,
    bytes calldata data
  ) internal override {
    // burn OpenSea legacy token; we could also transfer to MAKER and change the metadata
    // NOTE: if you allow burning editions, you will want to mint the correct {amount} into your new contract too
    _burn(legacyTokenId, amount);

    uint256 newTokenId = convertInternalToNewId(internalTokenId);

    // mint shiny new token
    NEW_CONTRACT.mint(owner, newTokenId);
  }

  // Here comes the fun part; mapping of the legacy NFT IDs to IDs in this contract
  // you can skip doing that if you don't care about keeping token ids consistent.
  // This reverts on invalid tokens as a safeguard to not migrate just any token.
  function convertInternalToNewId(uint256 id) pure public returns (uint256) {
    if (id < 10) {
      return id - 1;
    } // ...

    // reaching this means no valid ID was matched
    revert("Invalid Token ID");
  }
}

opensea-migration's People

Contributors

mediavrog avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.