How to Get Started With the Client Integration

How to Get Started With the Client Integration?

We will introduce some pieces of code in this section to help you make use of client integration. In this section, you can find the required functions written in JS or TS used to handle some specific operations within the Metis platform.

Note that all the client integration functions and code examples are for HTTP in JS or TS.

constructor(appId, accessToken, refreshToken, expiresIn, apiHost?)

Creating a new instance of the HttpClient.

const httpClient = new httpClient(
// The app id found on the application dashboard of Polis
"60f4f7e5ac31e3dccdcdecb5",
//The 0Auth2 Access token of your application
"3e2444385db44f1a802390f692041e92",
// The 0Auth2 refresh token of your application
"3eb18d851e414048b171ff53050b4fa2",
// Seconds until the accessToken expires
1800,
// The API host ip address
"localhost.localdomain"
);

Parameter Name

Parameter Type

Parameter Description

appId

string

The Id of the specific application on the Polis application dashboard

accessToken

string

0Auth2 API access_token of your specific application

refreshToken

string

The token which refreshes the access_token

expiresIn

number

Integer of seconds until API access_token expires

apiHost

string

IP of access

Returns

Return example for accessing the token and confirming the transaction.

sendTx(domain, chainid, fun, args?, succCallback?, errCallback?)

Sending a transaction onto the blockchain and calling a function within the smart contract.

Parameter Name

Parameter Type

Parameter Description

domain

string

Deployed smart contract name

chainid

number

Blockchain's chain ID that your contract is deployed on

fun

string

Name of the function to call within the deployed smart contract

args

array

Parameters to call the function above in order

succCallback?

function

The success function which is passed into the sendTx function to be called when execution is successful

errCallback?

function

The success function which is passed into the sendTx function to be called when execution results in an error

sendTx Return

sendTx Return example:

Sending a transaction onto the blockchain asynchronously and calling a method within a smart contract.

Parameter Name

Parameter Type

Parameter Description

domain

string

Deployed smart contract name

chainid

number

Blockchain's chain id that your contract is deployed on

fun

string

Name of the function that you are calling in the smart contract

args

array

Parameters that are needed to call the function above in order

sendTxAsync Return

An example of sending a transaction asynchronously.

Checking the final validity of a transaction before it is executed on chain.

Parameter Name

Parameter Type

Parameter Description

domain

string

Polis domain name

chainid

number

Blockchain's chain id that you deployed the contract on

address

string

Address of the caller of the transaction

fun

string

Name of the smart contract function called in this transaction

args

array

Parameters that are passed into the call of the function above

gas

string

The minimum gas for sending the tx on the blockchain

gasPrice

string

Gas price of the blockchain for the TX

fee

string

Gas fees for the specific TX

queryTx(chainid, tx, succCallback?, errCallback?)

Querying a transaction’s validity and calling a successful or an error message in execution.

Parameter Name

Parameter Type

Parameter Description

chainid

number

The blockchain's chain ID that the contract is deployed on

tx

string

Specific transaction hash

succCallback?

function

The function that is passed into queryTx to be called

errCallback

function

The function that is passed into queryTx to be called

queryTx Return

queryTx Return Example:

Querying transactions’ validity asynchronously to return a promise.

Parameter Name

Parameter Type

Parameter Description

chainid

number

The chain ID that the transaction is executed on

tx

string

The transaction hash

queryTxAsync Return

queryTxAsync Return Example:

Closing the dialog and calling the close() method without any parameters.

httpClient.closeConfirmDialogue();

error(msg)

Calling the error method and sending an error message to the console.

httpClient.error("Deployment Error");

Parameter Name

Parameter Type

Parameter Description

msg

string

An error message that will be logged into the console

Error Return

Error return example:

["socket client runtime error!", "Deployment Error"]

handleRefreshToken(callback?)

Using the refreshToken to obtain a new accessToken. The callback function should be called and log the message “Successful Refresh” in the console.

Parameter Name

Parameter Type

Parameter Description

callback?

function

A function that is passed into the handleRefreshtoken

handleRefreshTokenAsync()

Handling Refresh token asynchronously as input without any parameters.

await httpClient.handleRefreshTokenAsync()

log(obj)

Logging different variables.

// Passing string into the log function and logging them into the console

httpClient.log(["address: ", "0x11e575e473D552849b35d15A71C85bfFA511f45B"])

Parameter Name

Parameter Type

Parameter Description

obj

array

An array of variables that will be logged into console

Log Return

// Log return example

["address: ", "0x11e575e473D552849b35d15A71C85bfFA511f45B"]

Return Type

Return Description

void

Does not return any value

Please feel free to reach out to our Help Center if you have any technical questions.

Last updated