Skip to content
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

Demo: Create a wrapper that renders NFTs #45

Open
rihp opened this issue Apr 5, 2022 · 0 comments
Open

Demo: Create a wrapper that renders NFTs #45

rihp opened this issue Apr 5, 2022 · 0 comments

Comments

@rihp
Copy link
Contributor

rihp commented Apr 5, 2022

Smart-Contrace NFT Rendering (W/ Polywrap)

Idea inspired by zkachette & code snippets below written by dOrgJelli

Example Demo

Use the "blockies" library or something new/similar to generate a unique render (image, 3d, sound, video, etc) that is defined by the NFT's unique-id.

How could it work:

Use an NFT Contract

For example, use Artblocks Curated Contract on mainnet: 0xa7d8d9ef8d8ce8992df33d8b8cf4aebabd5bd270

Alternatively, deploy your own collection on Polygon or a testnet:

  • Collection should have 1,000+ tokens minted
  • Each NFT is an ERC721 with own unique id
  • Potentially, have it so each NFT has a "renderer" function defined (more on this below)

NFT Renderer

This is a simple program that is built using "Polywrap". Polywrap allows you to download & run custom code on-the-fly, regardless of what application you're using.

Polywrap Building

#import { Query } into Ethereum from "ens/ethereum.polywrap.io"
#import { Content } into Nft from "ens/nft-renderer.jpgmafia.io"

type Query {
  nftRender(
    contract: String!
    id: String!
  ): Nft_Content!
}
import {
    Ethereum_Query,
    Nft_Content,
    Input_nftRender
} from "./generated";
import { generateNoiseJpg } from "noise-generator";

export function nftRender(input: Input_nftRender): Nft_Content {
    
    // Get some custom properties
    const generation = Ethereum_Query.callContractView({
        address: input.contract,
        method: "getGeneration",
        args: {
            id: input.id
        }
    });
    
    const rawBytes = generateNoiseJpg(
      hash(input.contract + input.id + generation)
    );
    
    return {
      bytes: rawBytes,
      type: "jpg" // type-safe, only accepts valid values!
    }   
}

Publishing (IPFS + ETH)!

  1. Build your wrapper
build/
  query.wasm
  schema.graphql
  polywrap.json
  etc
  1. Deploy to IPFS
    polywrap deploy => wrap://ipfs/QmHASH
  2. Deploy the NFT contract
    hardhat deploy ./src/NtfWithCustomRenderer.sol
  3. Set the renderer in the NFT contract
    contract.setRenderer("wrap://ipfs/QmHASH")

Publishing (ETH-Only) !

  1. Build your wrapper
build/
  query.wasm
  schema.graphql
  polywrap.json
  etc
  1. Deploy the NFT contract
    hardhat deploy ./src/NtfWithCustomRenderer.sol
  2. Set the renderer in the NFT contract
contract.setRendererBytes(
  readDirectoryBytes("./build")
);

Rendering!

Inside your app:

const bytes = await client.invoke({
    // ETH only
    uri: "eth/0xNftWithCustomRenderer/getRenderer",
    // IPFS + ETH
    uri: "ipfs/QmHASH",
    module: "query",
    method: "nftRender",
    input: {
        contract: "0xCONTRACT",
        id: users_id
    }
});

browser.renderJpg(bytes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant