-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.ts
More file actions
46 lines (38 loc) · 1.35 KB
/
Copy pathsample.ts
File metadata and controls
46 lines (38 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'dotenv/config'
import { chromium } from 'playwright'
import fs from 'fs'
import { Keypair } from '@solana/web3.js'
import bs58 from 'bs58'
async function run() {
const payer = Keypair.fromSecretKey(
bs58.decode(process.env.PRIVATE_KEY_BASE58!)
)
const browser = await chromium.launch({ headless: true })
const page = await browser.newPage()
// Load local JS file
let script = fs.readFileSync('./dist/bundle.js', 'utf8')
script += `;(async () => {
const payer = Keypair.fromSecretKey(
bs58.decode("${process.env.PRIVATE_KEY_BASE58!}")
);
const wallet = PhantomWalletMock.create('https://kora-8cwrc2-fast-mainnet.helius-rpc.com', payer, 'confirmed');
await wallet.connect();
localStorage.setItem("userID", payer.publicKey.toBase58());
localStorage.setItem("wallet-immersive-mode", "false");
localStorage.setItem("walletName", '"Phantom"');
window.solana = wallet;
})()`
await page.goto(
'https://jup.ag/limit?sell=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v&buy=So11111111111111111111111111111111111111112'
)
await page.waitForLoadState('load')
// Inject before any page scripts
await page.evaluate(script)
const response = await page.waitForResponse(
'https://trigger.jup.ag/privy/wallets/' + payer.publicKey.toBase58()
)
const json = await response.json()
console.log(json)
browser.close()
}
run()