Created
August 14, 2022 12:47
-
-
Save ngundotra/8c1b788cf1b950d3c5cc861edace6f07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Metaplex, keypairIdentity, bundlrStorage } from '@metaplex-foundation/js'; | |
import { Connection, Keypair, clusterApiUrl } from '@solana/web3.js'; | |
import { readFileSync } from 'fs'; | |
async function sleep(delay: number) { | |
return new Promise((resolve) => { | |
setTimeout(() => resolve(null), delay); | |
}); | |
} | |
function kpFromFile(): Keypair { | |
const kpBytes = JSON.parse(readFileSync("/Users/<your username>/.config/solana/id.json").toString()); | |
return Keypair.fromSecretKey(Uint8Array.from(kpBytes)); | |
} | |
async function main() { | |
// const kp = Keypair.generate(); | |
const kp = kpFromFile(); | |
const connection = new Connection(clusterApiUrl("testnet"), "confirmed"); | |
const mpl = Metaplex.make(connection).use(keypairIdentity(kp)).use(bundlrStorage()); | |
// const txId = await connection.requestAirdrop(kp.publicKey, 1e9); | |
// console.log(kp.publicKey.toString(), "received 1 lamport:", txId); | |
await sleep(1000); | |
const nftTask = mpl.nfts().create({ | |
name: "Testy McTestFace", | |
uri: "<JSON_URI>", | |
sellerFeeBasisPoints: 500, | |
}); | |
const nftResult = await nftTask.run(); | |
console.log("Created nft:", nftResult.nft.mint.address.toString(), nftResult.tokenAddress.toString(), nftResult); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment