readApi.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. import { RPC_PATH } from './cnft-burn';
  6. // 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
  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(assetId: any, rpcUrl = RPC_PATH): Promise<any> {
  26. try {
  27. const axiosInstance = axios.create({
  28. baseURL: rpcUrl,
  29. });
  30. const response = await axiosInstance.post(rpcUrl, {
  31. jsonrpc: '2.0',
  32. method: 'getAssetProof',
  33. id: 'rpd-op-123',
  34. params: {
  35. id: assetId,
  36. },
  37. });
  38. return response.data.result;
  39. } catch (error) {
  40. console.error(error);
  41. }
  42. }