yihau / solana-web3-demo

a quick demo for solana web3

Home Page:https://yihau.github.io/solana-web3-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NFT in WebGL ?

Ben-v-starloop opened this issue · comments

Hello! I am trying to use your example of NFT, inside a WEBGL Unity Game.

import { programs } from "@metaplex/js";
import { Connection, PublicKey } from "@solana/web3.js";

// NFT is a mint. just like SRM, USDC ..., the only different is that NFT's supply is 1
//
// if we want to get NFT's metadata, first we need to know what is the mint address.
// here I take a random DAPE as an example
// https://explorer.solana.com/address/9MwGzSyuQRqmBHqmYwE6wbP3vzRBj4WWiYxWns3rkR7A
//
// tokenmeta is a PDA a which derived by mint address
// the formula is ['metadata', metadata_program_id, mint_id]
// is it totally fine to forget it because sdk already wrapped it for us

const connection = new Connection("https://api.mainnet-beta.solana.com");

async function main() {
  let mintPubkey = new PublicKey("9MwGzSyuQRqmBHqmYwE6wbP3vzRBj4WWiYxWns3rkR7A");
  let tokenmetaPubkey = await programs.metadata.Metadata.getPDA(mintPubkey);

  const tokenmeta = await programs.metadata.Metadata.load(connection, tokenmetaPubkey);
  console.log(tokenmeta);
}

main().then(
  () => process.exit(),
  (err) => {
    console.error(err);
    process.exit(-1);
  }
);

Basically I would need to plug your code, inside the body of the index.html page, and in the header I should embed this:

<script src="../metaplex.js"></script> <script src="../solanaweb3.js"></script>

Or something like that.

I can't embedd your

import { programs } from "@metaplex/js";
import { Connection, PublicKey } from "@solana/web3.js";

into the header of the HTML file.
How can Typescript libraries can be used in an HTML page?
Thanks!

I found some lib maybe you can take a look https://github.com/allartprotocol/unity-solana-wallet
I have no idea how to use typescript with unity sorry.