Last active
February 21, 2022 13:05
-
-
Save kyktommy/88eabf69f19da3606411edc6af98477c to your computer and use it in GitHub Desktop.
opensea automate add item, sell item, migrate
This file contains 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 puppeteer, { Page } from 'puppeteer'; | |
import dappeteer from '@chainsafe/dappeteer'; | |
import fs from 'fs'; | |
const METAMASK_SEED = '<your metamask seed>'; | |
const METAMASK_PASSWORD = '<your metamask password>'; | |
const collectionName = "<your collection name" | |
const collectionURL = `https://opensea.io/collection/${collectionName}/assets/create` | |
const connectWallet = async (page: Page, metamask) => { | |
console.log('start connect wallet'); | |
// Force list of wallets to refresh as otherwise OpenSea sometimes doesn't detect MetaMask properly | |
const moreButton = await page.$x('//button[contains(.,"Show more options")]'); | |
await moreButton[0].click(); | |
await page.waitForTimeout(1000); | |
// Find the MetaMask button and click it | |
const metaMaskButton = await page.$x( | |
'//button[.//span[contains(text(),"MetaMask")]]' | |
); | |
await metaMaskButton[0].click(); | |
await page.waitForTimeout(2000); | |
await metamask.approve(); | |
console.log('connected wallet'); | |
return; | |
} | |
const uploadImage = async (page: Page, file: string) => { | |
const elementHandle = await page.$("#media"); | |
await elementHandle.uploadFile(`images/${file}`); | |
return; | |
} | |
(async () => { // Async function because we need promises to do it | |
// Get an List with all images on images folder | |
// 1.jpg, 2.jpg | |
let files = await fs.promises.readdir("images/"); | |
files.shift() // WARN: just on macOS: remove the first file .DS_Store | |
files = files.sort((a, b) => { | |
const aa = a.replace('.jpg', '') | |
const bb = b.replace('.jpg', '') | |
return parseInt(aa, 10) - parseInt(bb, 0) | |
}) | |
const browser = await dappeteer.launch(puppeteer, {metamaskVersion: 'v10.1.1' }); // Launch the browser with metamask | |
const metamask = await dappeteer.setupMetamask(browser, { seed: METAMASK_SEED, password: METAMASK_PASSWORD }); // Add your secret phase here to metamask connect with your account | |
// 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 page.waitForTimeout(2000) | |
// Run our function to click on the Metamask button in the Opensea | |
await connectWallet(page, metamask) | |
await page.waitForTimeout(2000); | |
await metamask.sign(); | |
await page.bringToFront() | |
await page.waitForTimeout(2000); | |
await page.goto(collectionURL); | |
// 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 name = files[i].replace('.jpg', '') | |
const data = { | |
name: name, | |
price: 1 | |
} | |
console.log({ message: `start upload ${data.name}` }) | |
await page.bringToFront() | |
await page.goto(collectionURL); | |
await page.waitForSelector("#media"); | |
// 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, data.type); | |
await page.waitForTimeout(1000) | |
// Click on create asset button | |
const createBtn = await page.$x('//button[contains(.,"Create")]'); | |
await createBtn[0].click() | |
await page.waitForXPath('//h4[contains(text(),"You created")]'); | |
console.log({ message: `done upload ${data.name}`}) | |
// reload to get sell button | |
await page.reload() | |
await page.waitForTimeout(2000) | |
// sell it | |
await page.waitForXPath('//a[contains(text(),"Sell")]'); | |
const sellBtn = await page.$x('//a[contains(text(),"Sell")]'); | |
await sellBtn[0].click() | |
await page.waitForTimeout(1000) | |
// change duration to 6 months | |
await page.waitForSelector('.Blockreact__Block-sc-1xf18x6-0 .jPSCbX') | |
const durationBtn = await page.$('.Blockreact__Block-sc-1xf18x6-0 .jPSCbX') | |
durationBtn.click() | |
await page.waitForSelector('.DateRangePickerreact__StyledInput-sc-1j224wb-0 input') | |
await page.focus('.DateRangePickerreact__StyledInput-sc-1j224wb-0 input') | |
// await page.keyboard.type('0102') | |
await page.keyboard.press('Tab') | |
await page.keyboard.press('Tab') | |
await page.keyboard.type('0107') | |
await page.waitForTimeout(1000) | |
// change price | |
await page.focus('input[name="price"]'); | |
await page.keyboard.type("" + data.price) | |
await page.waitForTimeout(2000) | |
// submit sell | |
const submitBtn = await page.$x('//button[contains(.,"Complete listing")]'); | |
await submitBtn[0].click() | |
await page.waitForXPath('//h4[contains(text(),"Confirm")]', { timeout: 180 * 1000 }); | |
await page.waitForTimeout(2000) | |
// polygon | |
// click sign | |
// const signBtn = await page.$('.ActionPanel--content button.bhqEJb'); | |
// await signBtn.click() | |
await metamask.sign() | |
await metamask.page.waitForTimeout(2000) // wait for the transaction | |
await page.bringToFront() | |
await page.waitForXPath('//a[contains(text(),"View Item")]'); | |
console.log({ message: `Mint the NFT: ${data.name}`, fileName: files[i]}) | |
} | |
})(); |
This file contains 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 puppeteer, { Page } from 'puppeteer'; | |
import dappeteer from '@chainsafe/dappeteer'; | |
const METAMASK_SEED = '<your metamask seed>'; | |
const METAMASK_PASSWORD = '<your metamask password>'; | |
const migrateLisingURL = `https://opensea.io/account?tab=migrate_listings` | |
const connectWallet = async (page: Page, metamask) => { | |
console.log('start connect wallet'); | |
// Force list of wallets to refresh as otherwise OpenSea sometimes doesn't detect MetaMask properly | |
const moreButton = await page.$x('//button[contains(.,"Show more options")]'); | |
await moreButton[0].click(); | |
await page.waitForTimeout(1000); | |
// Find the MetaMask button and click it | |
const metaMaskButton = await page.$x( | |
'//button[.//span[contains(text(),"MetaMask")]]' | |
); | |
await metaMaskButton[0].click(); | |
await page.waitForTimeout(2000); | |
await metamask.approve(); | |
console.log('connected wallet'); | |
return; | |
} | |
;(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: METAMASK_SEED, password: METAMASK_PASSWORD }); // Add your secret phase here to metamask connect with your account | |
// Open the create assets url of the collection | |
const page = await browser.newPage(); | |
await page.goto(migrateLisingURL); | |
// Get the tabs and close the first tab openned by the dappeteer | |
const firstTabs = await browser.pages() | |
await firstTabs[0].close() | |
await page.waitForTimeout(2000) | |
// Run our function to click on the Metamask button in the Opensea | |
await connectWallet(page, metamask) | |
await page.waitForTimeout(2000); | |
await metamask.sign(); | |
await page.bringToFront() | |
await page.waitForTimeout(2000); | |
await page.goto(migrateLisingURL); | |
while(true) { | |
await page.bringToFront() | |
await page.goto(migrateLisingURL); | |
await page.waitForXPath('//button[contains(.,"Confirm")]') | |
const btn = await page.$x('//button[contains(.,"Confirm")]') | |
const clickIndex = parseInt(String(Math.random() * btn.length), 10) | |
await btn[clickIndex].click() | |
await page.waitForTimeout(1000) | |
await metamask.page.bringToFront() | |
await metamask.page.waitForTimeout(1000) | |
await metamask.page.reload() | |
await metamask.sign() | |
await metamask.page.waitForTimeout(2000) | |
} | |
})(); |
This file contains 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
{ | |
"name": "nft-auto", | |
"version": "1.0.0", | |
"main": "index.js", | |
"license": "MIT", | |
"dependencies": { | |
"@chainsafe/dappeteer": "2.3.0", | |
"esbuild": "^0.13.10", | |
"esbuild-register": "^3.0.0", | |
"puppeteer": "^10.4.0" | |
}, | |
"scripts": { | |
"add": "node -r esbuild-register ./src/add.ts", | |
"migrate": "node -r esbuild-register ./src/migrate.ts" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment