readApi.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // I recommend using a WrappedConnection for production
  2. // as it supports more readAPI functionality
  3. // this is just a subset of functions for quick availabiity
  4. import axios from "axios";
  5. // you might want to change that to your custom RPC endpoint as this endpoint is not going to work as it does not support DAS
  6. const RPC_PATH = "https://api.devnet.solana.com";
  7. export async function getAsset(assetId: any, rpcUrl = RPC_PATH): Promise<any> {
  8. try {
  9. const axiosInstance = axios.create({
  10. baseURL: rpcUrl,
  11. });
  12. const response = await axiosInstance.post(rpcUrl, {
  13. jsonrpc: "2.0",
  14. method: "getAsset",
  15. id: "rpd-op-123",
  16. params: {
  17. id: assetId,
  18. },
  19. });
  20. return response.data.result;
  21. } catch (error) {
  22. console.error(error);
  23. }
  24. }
  25. export async function getAssetProof(
  26. assetId: any,
  27. rpcUrl = RPC_PATH
  28. ): Promise<any> {
  29. try {
  30. const axiosInstance = axios.create({
  31. baseURL: rpcUrl,
  32. });
  33. const response = await axiosInstance.post(rpcUrl, {
  34. jsonrpc: "2.0",
  35. method: "getAssetProof",
  36. id: "rpd-op-123",
  37. params: {
  38. id: assetId,
  39. },
  40. });
  41. return response.data.result;
  42. } catch (error) {
  43. console.error(error);
  44. }
  45. }