Ola language
  • Introduction
  • 🏃‍♂️Quick Start
  • 👀Ola Examples
  • 👏Ola Language
    • Variables
    • Data Types
    • Operators
    • Control Flow
    • Functions
    • Event
    • Contracts
    • Interfaces and Librariese
    • Import
    • Comment Lines
    • Features TODO
  • Standard Libraries
    • CoreLib Functions
    • Prophet Functions
  • Ola Language ABI
  • Ola Compiler
    • Compiler Frontend
    • Compiler Backend
  • Ola Language Grammar
  • Appendix
Powered by GitBook
On this page
  • ABI specification
  • ABI encode function and params
Edit on GitHub

Ola Language ABI

In order to interact programmatically with compiled ola programs, Ola language supports passing arguments using an ABI.

To illustrate this, we'll use the following example program:


contract BookExample {
    struct Book {
        u32 book_id;
        string book_name;
    }

    fn createBook(u32 id, string name) -> (Book) {
        Book myBook = Book({
            book_name: name,
            book_id: id
        });
        return myBook;
    }

    fn getBookName(Book _book) -> (string) {
        return _book.book_name;
    }

    fn getBookId(Book _book) -> (u32) {
        u32 b = _book.book_id + 1;
        return b;
    }

}

ABI specification

When compiling a ola program, an ABI specification is generated and describes the interface of the program.

In this example, the ABI specification is:

[
  {
    "name": "createBook",
    "type": "function",
    "inputs": [
      {
        "name": "id",
        "type": "u32",
        "internalType": "u32"
      },
      {
        "name": "name",
        "type": "string",
        "internalType": "string"
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "tuple",
        "internalType": "struct BookExample.Book",
        "components": [
          {
            "name": "book_id",
            "type": "u32",
            "internalType": "u32"
          },
          {
            "name": "book_name",
            "type": "string",
            "internalType": "string"
          }
        ]
      }
    ]
  },
  {
    "name": "getBookName",
    "type": "function",
    "inputs": [
      {
        "name": "_book",
        "type": "tuple",
        "internalType": "struct BookExample.Book",
        "components": [
          {
            "name": "book_id",
            "type": "u32",
            "internalType": "u32"
          },
          {
            "name": "book_name",
            "type": "string",
            "internalType": "string"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "string",
        "internalType": "string"
      }
    ]
  },
  {
    "name": "getBookId",
    "type": "function",
    "inputs": [
      {
        "name": "_book",
        "type": "tuple",
        "internalType": "struct BookExample.Book",
        "components": [
          {
            "name": "book_id",
            "type": "u32",
            "internalType": "u32"
          },
          {
            "name": "book_name",
            "type": "string",
            "internalType": "string"
          }
        ]
      }
    ],
    "outputs": [
      {
        "name": "",
        "type": "u32",
        "internalType": "u32"
      }
    ]
  }
]

ABI encode function and params

We can use the tools provided by ola-lang-abi to generate function selectors and function parameters corresponding to ABI.

PreviousProphet FunctionsNextOla Compiler

Last updated 1 year ago

https://github.com/Sin7Y/ola-lang-abi/tree/main/examples