外海で10000のNFLを造る方法



外海への献身
あなたのすべてのNFFTを作成した後、より多くの最も難しいステップは多くのNFTSを多くのNFTSを大部分は契約なしで大量に公開することです.

それをするために、私はNPFsを鋳造するプロセスを自動化するためにPuppeteerを使用する私の倉庫を共有します、あなたはちょうどイメージ・フォルダファイルとすべてのミントにイメージ名を必要とします.下のリポジトリの使い方を教えます.

If you want to add another property on the mint time send me an email we can discuss it [email protected].



パッケージのインストール
まず、プロジェクトを実行するためにパッケージをインストールします.
yarn add @chainsafe/dappeteer puppeteer esbuild esbuild-register
The @chainsafe/dappeteer Memamask接続をMFTに自動化するのに役立つ.
The puppeteer 画像をアップロードして入力を入力します.
そして、我々は使用するつもりですesbuild and esbuild-register スクリプトを実行するには

スクリプトの作成
ファイルを作成しましょうscript.ts 最初のインポートを行い、最初の変数を追加します.
スクリプト.TS
import puppeteer, { Page } from 'puppeteer';
import dappeteer from '@chainsafe/dappeteer';
import fs from 'fs';

const collectionName = "Your Collection Name"
const collectionURL = `https://opensea.io/collection/${collectionName}/assets/create`
const openseaDescription = `Your description here`
const lockedContent = `Locked content text here`

ウォレット機能
だから、私たちのスクリプトがブラウザを開いたときにMetamask財布を選択するには、Metamaskボタンをクリックして財布に接続する機能を作成しましょう.
スクリプト.TS
const connectWallet = async (page: Page, metamask) => {
  const button = await page.$('button.dBFmez:first-child');
  await button.click();

  await metamask.approve();

  return;
}

アップロード画像機能を作成する
Create Nftページのイメージをアップロードするには、ページとファイルを受け取る関数を作成し、入力要素をHTMLに取り込み、画像をアップロードします.
スクリプト.TS
const uploadImage = async (page: Page, file: string) => {
  const elementHandle = await page.$("#media");
  await elementHandle.uploadFile(`images/${file}`);

  return;
}

ページタイムアウト機能を作成する
この関数は、アプリケーションでのフィリングやクリックを実行するスクリプトの時間を与えることです.
スクリプト.TS
const pageTimeout = async (time: number, page: Page) => {
  await page.waitForTimeout(time)
  return;
}

塗りつぶしフィールド関数を作成する
これは、各フィールドをCreate NFTページから取得し、それを入力する機能です.
この関数の実行手順
1 -フィールド名を入力します
2 -フィールド入力を入力します.
3 - unlockableコンテンツをオンにし、unlockableコンテンツのテキストを入力します.
多角形チェーンを選択
スクリプト.TS

const fillFields = async (page: Page, fileName: string) => {

// Get and fill in the input name
  await page.focus('#name')
  await page.keyboard.type(fileName)

  await pageTimeout(1000, page)

//Get and fill in the input name
  await page.$eval('#description', (el, value) => el.value = value, openseaDescription);
  await page.focus('#description')
  await page.keyboard.type(' ')

  await pageTimeout(1000, page)

// Click on the unlockable content checkbox
  await page.evaluate(() => {
    document.querySelector("#unlockable-content-toggle").parentElement.click();
  });

  await pageTimeout(1000, page)

// Fill in the unlockable content text
  await page.$eval('textarea[placeholder="Enter content (access key, code to redeem, link to a file, etc.)"]', (el, value) => el.value = value, lockedContent);
  await page.focus('textarea[placeholder="Enter content (access key, code to redeem, link to a file, etc.)"]')
  await page.keyboard.type(' ')

// Open the select chain input
  const input = await page.$("#chain")
  input.click()

  await pageTimeout(1000, page)

// Select the polygon chain
  await page.click('img[src="/static/images/logos/polygon.svg"]')

  return;
}

主関数の作成
この関数では、スクリプトを実行するためのすべての主な関数を作成します.
1 -オープンソースのメタメークを設定するにはDappeteerを実行します.
2 -画像フォルダファイルからファイルを取得します.
3 -最初のファイルを削除します.
4 -コレクションの作成資産ページを開きます.
5 - Connect財布機能を走らせてください
6 -イメージフォルダーの各イメージのループを実行します(1つずつの資産を作成する)
次の手順を参照してください
スクリプト.TS
(async () => { // Async function because we need promises to do it
  const browser = await dappeteer.launch(puppeteer, { metamaskVersion: 'v10.1.1' }); // Launch the browser with metamask
  const metamask = await dappeteer.setupMetamask(browser, { seed: "Secret phase here"}); // Add your secret phase here to metamask connect with your account
  const files = await fs.promises.readdir("images/"); // Get an List with all images on images folder
  files.shift() // WARN: just on macOS: remove the first file .DS_Store 

// Open the create assets url of the  collection
  const page = await browser.newPage();
  await page.goto(collectionURL);

// Get the tabs and close the first tab openned by the dappeteer
  const firstTabs = await browser.pages()
  await firstTabs[0].close()

  await pageTimeout(2000, page)

// Run our function to click on the Metamask button in the Opensea
  await connectWallet(page, metamask)

// Start the loop on each image of images folder
  for (let i = 0; i <= files.length ; i++) {
    const tabs = await browser.pages() // Get the tabs on each loop
    const data = {
      name: `Your Asset name here #${1 + i}`, // Add your NFT name (the count start on 1 and stop on the quantity of the files)
    }

// At the first time on loop you need to do an sign to create the assets 
    if(i === 0) {
      await tabs[1].bringToFront() // Move one tab
      await tabs[1].goto(collectionURL) // Change the page to collection url again

      await pageTimeout(2000, page)

      await metamask.sign() // Use the metamask to do the transaction
      await metamask.page.waitForTimeout(2000) // wait for the transaction
    }

// Now if not the first time, after creating the first NFT just open the create assets page again to create the second NFT and so sequentially.
    if(i === 0) {
      await tabs[1].bringToFront()
      await tabs[1].goto(collectionURL)
    } else {
      await tabs[1].bringToFront()
      await tabs[1].goto(collectionURL)
    }

    await pageTimeout(2000, page)

// Upload the current image file
    await uploadImage(page, files[i]);

// Fill the fields using the asset name with the count
    await fillFields(page, data.name);

// Click on create asset button
    const button = await page.$('.AssetForm--action button');
    await button.click()

    await pageTimeout(4000, page)

// Rename the image name to know if already is completed
    fs.renameSync(`images/${files[i]}`, `images/completed-${files[i]}`)

    console.log({ message: `Mint the NFT: ${data.name}`, fileName: files[i]})
    console.log(`Mint the NFT: ${data.name}`)
  }

  console.log('Minted all NFTs with success')
})();
用意!では設定しましょうpackage.json スクリプトを1行で実行するには
パッケージ.JSON
{
  "name": "node",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@chainsafe/dappeteer": "^2.2.0",
    "dappeteer": "^1.0.0",
    "esbuild": "^0.13.10",
    "esbuild-register": "^3.0.0",
    "puppeteer": "^10.4.0"
  },
  "scripts": {
    "es": "node -r esbuild-register"
  }
}
スクリプトを実行するには、単にCLIを実行します.
yarn es ./src/script.ts

ダウンロードする
まず、私のリポジトリをダウンロードする必要がありますhere これにはNFHを埋め込むスクリプトが含まれます.
スターマイリポジトリhere
これは、今ではPetpeteerは、1つのすべてのあなたのNFFTの1つを作成し、非常に高速です.

それだ!
フォローミーオン
マイGithub