dOrgTech / homebase-app

Homebase is a web application that enables users to create and manage/use DAOs on the Tezos blockchain.
https://tezos-homebase.io/
MIT License
45 stars 13 forks source link

ACI webapp backend #793

Open EightRice opened 8 months ago

EightRice commented 8 months ago

Upon receiving a contract address, the app fetches the contract's details using Taquito's Tezos.contract.at(contractAddress). The backend parses the contract's script to identify available endpoints and their parameters. This data is structured and sent back to the frontend, enabling the dynamic form generation. The contract call is then constructed and submitted as payload to within a proposal of type Arbitrary Contract Interaction.

Here is a simplified example of the implementation:

Starting point:

const TezosToolkit = require('@taquito/taquito').TezosToolkit;

// Initialize Taquito with the RPC endpoint
const tezos = new TezosToolkit('https://your-preferred-rpc-here.com');

async function getContractEndpoints(contractAddress) {
  try {
    const contract = await tezos.contract.at(contractAddress);
    const script = contract.script.code; // This contains the contract's code including entry points
    const endpoints = parseContractScript(script); 
    return endpoints;
  } catch (error) {
    console.error('Error fetching contract:', error);
  }
}

We can use as inspiration the working implementation of TzSafe. Their starting point is here

To create the parseContractScript method, we look at the structure of parameters as a tree, so we traverse from root. The implementation is available here.

akdorg commented 8 months ago

Assigned to @ashutoshpw & @EightRice