Skip to content

ora-io/web3.js-plugin-ora

Repository files navigation

Web3.js ORA Plugin

ES Version Node Version

This is a web3.js 4.x plugin for interacting with ORA Ethereum contracts.

Prerequisites

Installation

yarn add @ora-io/web3-plugin-ora

Using this plugin

Installing Version 4.x of web3

When adding the web3 package to your project, make sure to use version 4.x:

NOTE
If 4.x was already released, you are good to just use web3 without appending anything to it.

To verify you have the correct web3 version installed, after adding the package to your project (the above commands), look at the versions listed in your project's package.json under the dependencies section, it should contain version 4.x similar to:

"dependencies": {
	"web3": "4.0.3"
}

Registering the Plugin with a web3.js Instance

After importing ORAPlugin from @ora-io/web3-plugin-ora and Web3 from web3, register an instance of ORAPlugin with an instance of Web3 like so:

import { ORAPlugin } from '@ora-io/web3-plugin-ora';
import { Web3 } from 'web3';

const web3 = new Web3('YOUR_PROVIDER_URL');
const oraPlugin = new ORAPlugin();

web3.registerPlugin(oraPlugin);

More information about registering web3.js plugins can be found here.

Plugin Methods

ORAPlugin supports method for getting AI inference results from all supported chains. When interacting with the plugin, users need to specify which chain to interact with.

getAIResult

public async getAIResult(
    promptAddress: PromptAddresses,
    modelId: Models,
    prompt: string,
    promptAbi: ContractAbi = this.defaultPromptAbi,
): {
    result: string
}

defaultPromptAbi can be found here.

The getAIResult accepts several inputs:

  • promptAddress - tells plugin which prompt contract to interact with
  • modelId - speficies the AI model which will return inference results
  • prompt - user prompt string for the inference call
  • promptAbi optional parameter for specifying prompt contract ABI (this parameter is defaulted to defaultPromptAbi).

Under the hood, this method is calling the getAIResult on the Prompt contract for the specified model and prompt. Tutorial on how to interact with ORA's Onchain AI Oracle can be found here.

import { ORAPlugin, PromptAddresses, Models } from '@ora-io/web3-plugin-ora';
import { Web3 } from 'web3';

const web3 = new Web3('YOUR_PROVIDER_URL');
const oraPlugin = new ORAPlugin();

web3.registerPlugin(oraPlugin);

const inferenceResult = await web3.ora.getAIResult(PromptAddresses.MAINNET, Models.STABLE_DIFFUSION, "Generate image of btc");
console.log(inferenceResult)

Found an issue or have a question or suggestion

Run the tests

  1. Clone the repo
  2. Run yarn to install dependencies
    • If you receive the following warning, please remove the file package-lock.json and make sure to run yarn to install dependencies instead of npm i:
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
  1. Run the tests:
  • yarn test: Runs the mocked tests that do not make a network request using the Jest framework

Useful links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published