Skip to main content

Relayer Methods

Imports needed for these methods:

import { Relayer } from "@abstraxn/relayer";

const relayerInstance = new Relayer({
relayerUrl: "YOUR_RELAYER_URL",
signer: signer,
chainId: ChainId.POLYGON_AMOY,
provider: provider,
});

Following are the methods that can be call on Relayer instance

buildRelayerTx

Builds a relayer transaction by encoding the function call and signing it.

Usage

const txParams = {
abi: contractAbi,
contractAddress: "0xContractAddress",
method: "transfer",
args: ["0xRecipientAddress", ethers.parseUnits("1", 18)],
};

const txData = await relayer.buildRelayerTx(txParams);
console.log("Transaction Data:", txData);

Parameters

interface BuildRelayerTxParams {
abi: any; // The contract ABI
contractAddress: string; // The contract address
method: string; // The function to call
args: any[]; // Function arguments
}

Returns

Promise<BuildRelayerTxResponse>: It returns an object containing the transaction values.

type BuildRelayerTxResponse = {
userAddress: string;
functionSignature: BytesLike
signature: BytesLike;
data:BytesLike;
chainId: ChainId;
contractAddress: string;
};

sendRelayerTx

Sends a signed relayer transaction to the relayer service.

Usage

const response = await relayer.sendRelayerTx({
userAddress: txData.userAddress,
signature: txData.signature,
contractAddress: txData.contractAddress,
chainId: txData.chainId,
});

console.log("Transaction ID:", response.transactionId);

Parameters

interface SendRelayerTxParams {
userAddress: string; // User's Ethereum address
functionSignature: BytesLike // Function signature
signature: string; // Signed transaction hash
contractAddress: string; // Contract address
chainId: number; // Chain ID
}

Returns

Promise<SendRelayerResponse>: It returns an object containing the transaction status.

type SendRelayerResponse = {
jsonrpc: string;
id: number;
message: string;
result: string;
error?: JsonRpcError;
};

getRelayerTxStatus

Retrieves the status of a relayer transaction.

Usage

const status = await relayer.getRelayerTxStatus(response.transactionId);
console.log("Transaction Status:", status);

Parameters

interface GetRelayerTxStatusParams {
transactionId: string; // Transaction ID to check
}

Returns

Promise<GetRelayerTxStatusResponse>: It returns an object containing the transaction status.

type GetRelayerTxStatusResponse = {
jsonrpc: string;
id: number;
result: RelayerTxStatus;
error?: JsonRpcError;
};