Get Function Integration

Follow the steps to integrate the view / read/ get function.

frontend/
    ├───components
    │   └───ui
    ├───entry-functions
    ├───lib
    ├───utils
    ├───view-functions
    ├───App.tsx
    ├───index.tsx

Navigate to the utils Directory and create a new TypeScript file in this directory. You might name it something like getFunction.ts

// src/utils/getFunction.ts

import { aptosClient } from "./aptosClient";

export const getFunction = async (accountAddress: string) => {
  try {
    const resourceType = "0xYourContractAddress::your_module::your_function_name";

    // Updated to pass an object with the expected properties
    const response = await aptosClient().getAccountResource({
      accountAddress,
      resourceType
    });
    console.log(response);
    
    return response && response.entries ? true : false;
  } catch (error) {
    console.error("Error checking if list exists:", error);
    return false;
  }
};

Here Replace,

0xYourContractAddress with your contract address (module address)

your_module with your module name (contract name)

your_function_name with your function name you need to call.

Now in App.tsx call the function like this:

The example App.tsx code is:

With this the get function is successfully integrated.

Integrating Aptos Move contracts can be a bit complex, but it is manageable with the right tools and approach. So you are in the right place, this will make it easier to integrate Move contracts.

Last updated