Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//Solana and token variables
export const USE_MAINNET = false;
export const VERIFIED_CREATOR = "AHx6cQKhJQ6vV9zhb37B7gKtRRGDuLtTfNWgvMiLDJp7";
export const TOKEN_TO_SEND = "toKPe7ENJiRBANPLnnp4dHs7ccFyHRg2oSEPdDfumg8";
export const AMOUNT_TO_SEND = 42000000000; // including decimals

//Filename inputs and outputs
export const KEYPAIR_FILE = "C:\\Users\\loopc\\wkdir\\DEVkasD4qwUJQ8LS7rcJHcGDQQzrEtWgk2jB6v5FHngo.json";
export const PROGRESS_FILE_PATH = "./progress.json";
export const ERROR_FILE_PATH = "./error.json";

//secondary Market wallets
export const MAGIC_EDEN_ADDRESS = "GUfCR9mK6azb9vcpsxgXyj7XRPAKJd4KMHTTVvtncGgp";
export const MAGIC_EDEN_ESCROW = "1BWutmTvYPwDtmw9abTkS4Ssr8no61spGAvW1X6NDix";
44 changes: 31 additions & 13 deletions executeAirdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ import * as web3 from '@solana/web3.js';
import * as anchor from "@project-serum/anchor";
import * as splToken from "@solana/spl-token";
const fs = require('fs');
import { readJson, writeJson } from "./prepareAirdrop";
import { ERROR_FILE_PATH, USE_MAINNET, KEYPAIR_FILE, MAGIC_EDEN_ADDRESS, MAGIC_EDEN_ESCROW } from './constants';
import { TokenInfo } from './tokenInfo';

import { TokenInfo, readJson, writeJson } from "./prepareAirdrop";

const USE_MAINNET = false;
const MAGIC_EDEN_ADDRESS = "GUfCR9mK6azb9vcpsxgXyj7XRPAKJd4KMHTTVvtncGgp";
export function writeErrors(data: TokenInfo[]){
let json = JSON.stringify(data);
fs.writeFileSync(ERROR_FILE_PATH, json);
}

async function sendToken(connection: web3.Connection, dropInfo: TokenInfo, sender: web3.Keypair): Promise<string>{

if(!dropInfo.sendableAmount || !dropInfo.sendableTokenMint || !dropInfo.owner) return "";
if(!dropInfo.sendableAmount || !dropInfo.sendableTokenMint || !dropInfo.ownerWallet) return "";

const mint = new web3.PublicKey(dropInfo.sendableTokenMint);
const owner = new web3.PublicKey(dropInfo.owner);
const owner = new web3.PublicKey(dropInfo.ownerWallet);


const transaction = new web3.Transaction();
Expand Down Expand Up @@ -56,7 +59,7 @@ async function sendToken(connection: web3.Connection, dropInfo: TokenInfo, sende
)
transaction.add(transferInstruction);

console.log("Sending form", sourceAccount.toBase58(),"to", destinationAccount.toBase58());
console.log("Sending from", sourceAccount.toBase58(),"to", destinationAccount.toBase58());

const txid = await web3.sendAndConfirmTransaction(
connection, transaction, [sender], { commitment: 'confirmed' });
Expand All @@ -73,7 +76,8 @@ export function loadWalletKey(keypairFile:string): web3.Keypair {
);
console.log(`using wallet: ${loaded.publicKey}`);
return loaded;
}
}


async function main() {

Expand All @@ -82,26 +86,40 @@ async function main() {

const allInfo = readJson();

const myKeypairFile = "C:\\Users\\loopc\\wkdir\\DEVkasD4qwUJQ8LS7rcJHcGDQQzrEtWgk2jB6v5FHngo.json";
const sender = loadWalletKey(myKeypairFile);
const sender = loadWalletKey(KEYPAIR_FILE);

//const txid = await sendToken(c, allInfo[0], sender);
//console.log(txid);
//return;


let success = 0;
let errors = 0;
let errorTransactions: TokenInfo[] = [];
for (let i = 0; i<allInfo.length; i++){
if(!allInfo[i].txid){
if(allInfo[i].owner === MAGIC_EDEN_ADDRESS) {
if(allInfo[i].ownerWallet === MAGIC_EDEN_ADDRESS || allInfo[i].ownerWallet === MAGIC_EDEN_ESCROW) {
console.log("skipping MagicEden address...");
continue;
}
const txid = await sendToken(c, allInfo[i], sender);
const txid = await sendToken(c, allInfo[i], sender).then((txn) => {
success++;
return txn;
}).catch( err => {
errors++;
console.log(err);
//unfortunately I didn't figure out how to get the txn id from the error, but the wallet is easy enough to look at
errorTransactions.push(allInfo[i]);
return "error or timeout";
});
allInfo[i].txid = txid;
writeJson(allInfo);
console.log(txid);
// console.log(txid);
await new Promise(f => setTimeout(f, 500));
}
}
writeErrors(errorTransactions);
console.log(`${success} successful transactions and ${errors} error/timeout transactions`);

}

Expand Down
34 changes: 7 additions & 27 deletions prepareAirdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,12 @@ import * as anchor from "@project-serum/anchor";
import { assert } from 'console';
import * as splToken from "@solana/spl-token";
import { token } from '@project-serum/anchor/dist/cjs/utils';
const fs = require('fs');

const VERIFIED_CREATOR = "AHx6cQKhJQ6vV9zhb37B7gKtRRGDuLtTfNWgvMiLDJp7";
const TOKEN_TO_SEND = "toKPe7ENJiRBANPLnnp4dHs7ccFyHRg2oSEPdDfumg8";
const AMOUNT_TO_SEND = 42000000000; // including decimans

export const PROGRESS_FILE_PATH = "./progress.json";

export class TokenInfo {
metadataAccount: string;
nftTokenMint: string;
nftName: string | undefined;
owner: string | undefined;
sendableTokenMint: string | undefined;
sendableAmount: number | undefined;
txid: string | undefined;

constructor(metadataAccount: string, tokenMint: string) {
this.metadataAccount = metadataAccount;
this.nftTokenMint = tokenMint;
}
import * as fs from 'fs';
import { TokenInfo } from './tokenInfo';
import { PROGRESS_FILE_PATH, AMOUNT_TO_SEND, TOKEN_TO_SEND, VERIFIED_CREATOR } from './constants';



show(){
console.log(this.metadataAccount + " -> " + this.nftTokenMint +' -> '+ this.owner);
}
}

export function writeJson(data: TokenInfo[]){
let json = JSON.stringify(data);
Expand Down Expand Up @@ -143,8 +123,8 @@ async function main(){

console.log("finding owners...")
allInfo.forEach(async tokenInfo => {
if (!tokenInfo.owner) {
tokenInfo.owner = await (await getOwnerForNFT(c, tokenInfo.nftTokenMint)).toBase58();
if (!tokenInfo.ownerWallet) {
tokenInfo.ownerWallet = await (await getOwnerForNFT(c, tokenInfo.nftTokenMint)).toBase58();
writeJson(allInfo);
}
});
Expand Down
19 changes: 19 additions & 0 deletions tokenInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

export class TokenInfo {
metadataAccount: string;
nftTokenMint: string;
nftName: string | undefined;
ownerWallet: string | undefined;
sendableTokenMint: string | undefined;
sendableAmount: number | undefined;
txid: string | undefined;

constructor(metadataAccount: string, tokenMint: string) {
this.metadataAccount = metadataAccount;
this.nftTokenMint = tokenMint;
}

show(){
console.log(this.metadataAccount + " -> " + this.nftTokenMint +' -> '+ this.ownerWallet);
}
}