test_web3.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const axios = require('axios');
  2. const web3 = require('@solana/web3.js');
  3. const fs = require("fs-extra");
  4. const { ReturnData } = require('@triton-one/yellowstone-grpc/dist/grpc/solana-storage');
  5. let swap_url = "https://solana-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS";
  6. let swap_connection = new web3.Connection("https://solana-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS", {
  7. commitment: "confirmed",
  8. });
  9. let sign = "3p2nQh1AfYsXFqBE59z2LsKB1Sv9JM7kjCS3GnD3bFw8VDN6z7Va7Kvjosdkt9tvesR68n52Q1y4sTLvhFFJsmyB"
  10. function guid() {
  11. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
  12. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  13. return v.toString(16);
  14. });
  15. }
  16. const listen_axios_config = {
  17. headers: { 'accept': 'application/json', 'content-type': 'application/json' },
  18. timeout: 3000,
  19. }
  20. async function main() {
  21. // let str_dalao_address = '7T1kJcKi5tYA2Vpza1BQnfShSsFCmyVBnxbncqHoEUqAa'
  22. // let listen_body_data = `{"id":"${guid()}","jsonrpc":"2.0","method":"getSignaturesForAddress","params":["${str_dalao_address}",{"limit":5, "commitment": "confirmed"}]}`;
  23. // let requestSignatures = await axios.post(swap_url, listen_body_data, listen_axios_config);
  24. // if (requestSignatures.status != 200) {
  25. // console.log(``)
  26. // return;
  27. // }
  28. // else if (requestSignatures.status == 200 && requestSignatures.error) {
  29. // throw new Error(requestSignatures.error.message);
  30. // }
  31. // console.log("yes")
  32. // requestSignatures = requestSignatures.data.result;
  33. // requestSignatures = requestSignatures.data;
  34. // console.log(requestSignatures);
  35. // let sign = '3pmidzXXVgtVPkLABbfurd3hqShFdib4d2epAz3zToeDi9uFbc6pkF79JH9axuGTtaDqwjDy8U9wLmXRy9b278pf'
  36. // obj_transaction = await swap_connection.getTransaction(sign, { commitment: "confirmed", maxSupportedTransactionVersion: 0 });
  37. // fs.writeJSONSync(`${sign}_obj_transaction.json`, obj_transaction, { spaces: 4 });
  38. // console.log(obj_transaction)
  39. let walletTokenAccount;
  40. walletTokenAccount = await swap_connection.getTokenAccountsByOwner(new web3.PublicKey("EuCYZeczx4L2y8HozZRgNsp17UtmeuN1gzBDn2ubW71k"), {
  41. programId: new web3.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
  42. mint: new web3.PublicKey("9UvushzXmQ7Xz6bEBReQtbHdgUXru3jBTe9SfaPts1Qe")
  43. });
  44. console.log(walletTokenAccount.value)
  45. // let str_ammid = "AiyRewCvnCWaJuCE851bQZP5LQeT11uVgKCASYZAfEHp"
  46. // const account = await swap_connection.getAccountInfo(new web3.PublicKey(str_ammid));
  47. // console.log(account)
  48. // let web3pub_dalaoaddd = new web3.PublicKey('GFUS44ebiF6YQ5FZQ9dXZVFba69rEuTqLwXcUFvVxVTD')
  49. // let requestSignatures = await swap_connection.getSignaturesForAddress(web3pub_dalaoaddd, {
  50. // limit: 5,
  51. // }, 'confirmed');
  52. // console.log(requestSignatures);
  53. }
  54. main()