Skip to content

Instantly share code, notes, and snippets.

@k0d3d
Last active July 6, 2022 20:10
Show Gist options
  • Save k0d3d/8e61390413c7353d06509e00146de41c to your computer and use it in GitHub Desktop.
Save k0d3d/8e61390413c7353d06509e00146de41c to your computer and use it in GitHub Desktop.
import * as solanaWeb3 from '@solana/web3.js';
const theblockchainapi = require('theblockchainapi')
const jsonfile = require('jsonfile')
let defaultClient = theblockchainapi.ApiClient.instance;
let APIKeyID = defaultClient.authentications['APIKeyID'];
let APISecretKey = defaultClient.authentications['APISecretKey'];
APIKeyID.apiKey = 'xxx';
APISecretKey.apiKey = 'xxx';
const conn = new solanaWeb3.Connection(
'https://xxx-xxx-paper.solana-mainnet.quiknode.pro/xxx/',
'finalized'
);
let apiInstance = new theblockchainapi.SolanaTransactionApi();
let network = 'mainnet-beta'; // String | The network ID (devnet, mainnet-beta)
async function getTransactionsOfAddress(address: PublicKeyInitData, options: any, connection: { getConfirmedSignaturesForAddress2: (arg0: PublicKey, arg1: any) => any; getConfirmedTransaction: (arg0: any) => any; }) {
// console.log({ address, options });
try {
const publicKey = new PublicKey(address);
const transSignatures =
await connection.getConfirmedSignaturesForAddress2(publicKey, options);
// console.log({ transSignatures });
const transactions = [];
for (let i = 0; i < transSignatures.length; i++) {
const signature = transSignatures[i].signature;
const confirmedTransaction = await connection.getConfirmedTransaction(
signature,
);
if (confirmedTransaction) {
const { meta } = confirmedTransaction;
if (meta) {
const oldBalance = meta.preBalances;
const newBalance = meta.postBalances;
const amount = oldBalance[0] - newBalance[0];
const transWithSignature = {
signature,
...confirmedTransaction,
fees: meta?.fee,
amount,
};
transactions.push(transWithSignature);
}
}
}
return transactions;
} catch (err) {
throw err;
}
}
(async () => {
// Create connection
const masterEditionAddresses = [
'4QSNp8eMPQnXNV3BTHqn5QAAG48sND7Ap3ea8yGnGY1E',
'F1RctUkkV5SW1viemL6ZpqBoKSdGVTLQxcUdVSxiGKMj'
]
let transactionSignatures = [];
let mintAddresses = []
try {
for (const address of masterEditionAddresses) {
transactionSignatures = await getTransactionsOfAddress( new solanaWeb3.PublicKey(address), {}, conn)
}
} catch (e) {
console.log('Error getting tx for master edition')
console.log(e)
}
try {
for (const tx of transactionSignatures) {
const solanaTx = await apiInstance.solanaGetTransaction(network, tx.signature)
//filter out failed tx
if (solanaTx.result.meta.err || solanaTx.result.meta.status._err ) {
return
}
const instructions1 = solanaTx.result.transaction.message.instructions
const instructions2 = solanaTx.result.meta.inner_instructions[0].instructions
const mintAddress1 = instructions1.find( (i:any) => {
return i.parsed?.type == "mintTo"
})
const mintAddress2 = instructions2.find( (i:any) => {
return i.parsed?.info.authority_type == "mintTokens"
})
mintAddresses.push( mintAddress1 )
mintAddresses.push( mintAddress2 )
}
} catch(e) {
console.log(e)
}
mintAddresses = mintAddresses.filter(add => add).map(add => {
return {
mint: add.parsed.info.mint
}
})
const outputFile = 'listOfMintAddresses.json'
await jsonfile.writeFile(outputFile, mintAddresses, { spaces: 2 } );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment