> For the complete documentation index, see [llms.txt](https://0xgaslesss-organization.gitbook.io/0xgasless-sdk-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xgaslesss-organization.gitbook.io/0xgasless-sdk-docs/sending-transactions/sending-batch-transaction-using-telegram.md).

# Sending Batch Transaction (using telegram)

#### Step 1: Creating the Batch Transaction

After initializing the SDK, you can create an array of batch transactions  using the `BatchUserOperationCallData` interface. This array represents the transactions you want to send. Here's an example:

```javascript
import { BatchUserOperationCallData, UserOperationCallData, sendUserOp } from '@0xgasless/0xgasless-aa-sdk';
import { ethers } from 'ethers';

// Replace with the contract address and ABI of the smart contract you want to interact with
const contractAddress = '0xContractAddress'; // Replace with the contract address
const contractABI = [
    // Define the ABI of the contract, including function definitions
    // Example: { "constant": false, "inputs": [...], "name": "functionName", "outputs": [...], "type": "function" }
];

// Create an instance of the contract
const contract = new ethers.Contract(contractAddress, contractABI);

// Specify the function you want to call and its parameters
const functionName = 'functionName'; // Replace with the name of the function you want to call
const functionParams = ['param1', 'param2']; // Replace with the function's parameters

// Encode the function call data
const functionInterface = new ethers.utils.Interface(contractABI);
const data = functionInterface.encodeFunctionData(functionName, functionParams);

// Create a transaction object
const transaction1: UserOperationCallData = {
    target: '0xRecipientAddress', // Replace with the recipient's Ethereum address
    data: data, // Replace with the transaction data in hexadecimal format
    value: BigInt('1000000000000000000'), // Optional: Replace with the amount in wei (e.g., 1 ETH)
};

const transaction2: UserOperationCallData = {
    target: '0xRecipientAddress', // Replace with the recipient's Ethereum address
    data: data, // Replace with the transaction data in hexadecimal format
};

const transactions = [transaction1, transaction2]

```

In this code:

* We import the `UserOperationCallData` interface to define the structure of the transaction object.
* `transactions` is an object that contains the transactions with `target` (recipient's Ethereum address), `data` (transaction data in hexadecimal format), and an optional `value` field for the transaction amount in wei.

#### Step 2: Prepare UserOperation and Send OTP on User's Telegram

Now that you have the transactions array, to send userOp there are 2 steps.

1. **Prepare UserOp and send OTP on telegram to user:**

First, call `prepareUserOpBatch`function on SDK with transactions as an argument to it. It will return with OTP sent status as `success: true/false` and `requestId`.

User will receive OTP on telegram which has to be sent in next step. Implement functionality to get the OTP from user as per your choice.

```typescript
const { requestId, otpSent } = await sdk.prepareUserOpBatch(transactions);
console.log("prepareUserOp",requestId,otpSent);
```

2. #### Send the Transaction using `sendUserOp` by passing requestId and OTP

```javascript
try {
    const requestId = <requestId>;
    const otp = <otp>;
    const { userOpHash, transactionHash } = await client.sendUserOp(requestId, otp);
    console.log('UserOp Hash:', userOpHash);
    console.log('Transaction Hash:', txHash);
    console.log('Transaction sent successfully');
} catch (error) {
    console.error('Transaction failed:', error);
}
```

In this code:

* `sendUserOp` takes 2 arguments: requestId and OTP.
* The `await client.sendUserOp(requestId, otp)` call sends the requestId and OTP  and returns an object containing both the `userOpHash` and `transactionHash`.
* The `userOpHash` is the hash of the user operation, and transactionHash is the hash of the underlying transaction.
* Both hashes are logged to the console for your reference.

With these steps, you can successfully send a transaction using Telegram and capture both the user operation hash and the transaction hash using the 0xGasless AA SDK.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://0xgaslesss-organization.gitbook.io/0xgasless-sdk-docs/sending-transactions/sending-batch-transaction-using-telegram.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
