# How to add a message input to TransactionRequestLike

**URL:** <https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949>\
**Category:** TypeScript SDK\
**Created:** [October 31, 2024, 11:01am UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949 "2024-10-31T11:01:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antony](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/antony/32/108_2.png) [@Antony](https://forum.fuel.network/u/Antony)\
**Post date:** [October 31, 2024, 11:01am UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949/1 "2024-10-31T11:01:24Z")

</div>

Hi All,  
In typescript and working with the FuelConnector, one of the parameters the FuelConnector `sendTransaction()` function takes is a TransactionRequestLike.

```auto
  sendTransaction(address: string, transaction: TransactionRequestLike): Promise<string>;

```

If i have set up the following dummy `TransactionRequestLike` tx, how can i add a Message input to the this type?

```auto
// as an example:

// Dummy tx:
  const script = Uint8Array.from([1, 2, 3, 4]);
  const scriptData = Uint8Array.from([5, 6]);
  const txRequestLike: TransactionRequestLike = {
    type: TransactionType.Script,
    script,
    scriptData,
    tip: 1,
    gasLimit: 10000,
    maturity: 1,
    inputs: [],
    outputs: [],
    witnesses: [],
  };

 // ... then sends it off in ...

const result = await currentConnector?.sendTransaction(
  currentAccount,
  txRequestLike,
);

```

I can only find references to adding a Message to a `ScriptTransactionRequest` in `transaction-request.ts`, I realize these data structures are not quite the same and have different purposes. Are there any examples of adding a Message (or request to have a message added) to `TransactionRequestLike` floating around?

snip from fuels-ts:  
packages/account/src/providers/transaction-request/transaction-request.ts

```auto
  /**
   * Adds a single message input to the transaction and a change output for the
   * asset against the message
   *
   * @param message - Message resource.
   */
  addMessageInput(message: Message | MessageCoin) {
    const { recipient, sender, amount, predicate, nonce, predicateData } = message;

    let witnessIndex;

    if (message.predicate) {
      witnessIndex = 0;
    } else {
      witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);

      // Insert a dummy witness if no witness exists
      if (typeof witnessIndex !== 'number') {
        witnessIndex = this.addEmptyWitness();
      }
    }

    const input: MessageTransactionRequestInput = {
      nonce,
      type: InputType.Message,
      sender: sender.toB256(),
      recipient: recipient.toB256(),
      data: isMessageCoin(message) ? '0x' : message.data,
      amount,
      witnessIndex,
      predicate,
      predicateData,
    };

    // Insert the Input
    this.pushInput(input);

    // Insert a ChangeOutput if it does not exist
    if (isMessageCoin(message)) {
      this.addChangeOutput(recipient, message.assetId);
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Antony](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/antony/32/108_2.png) [@Antony](https://forum.fuel.network/u/Antony)\
**Post date:** [October 31, 2024, 11:37am UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949/2 "2024-10-31T11:37:47Z")

</div>

Ok i think it could be something like:

```auto

import { TransactionRequestLike } from "@fuels";
import { InputType, TransactionType } from '@fuel-ts/transactions';
import { bn } from '@fuel-ts/math';
import { Address } from '@fuel-ts/address';

...

  const senderAddress = Address.fromRandom();
  const recipientAddress = Address.fromRandom();

  const txRequestLike: TransactionRequestLike = {
    type: TransactionType.Script,
    script: Uint8Array.from([1, 2, 3, 4]),
    scriptData: Uint8Array.from([5, 6]),
    tip: 1,
    gasLimit: 10000,
    maturity: 1,
    inputs: [
      {
        type: InputType.Message,
        amount: bn(100), 
        sender: senderAddress.toB256(), 
        recipient: recipientAddress.toB256(), 
        data: '0x', 
        nonce: '0x0000000000000000000000000000000000000000000000000000000000000000', // Message nonce
        witnessIndex: 0, 
        // Optional predicate fields
        predicate: '0x', 
        predicateData: '0x', 
      }
    ],
    outputs: [],
    witnesses: [
      '0x0000000000000000000000000000000000000000000000000000000000000000' +
      '0000000000000000000000000000000000000000000000000000000000000000'
    ],
  };

```

---

<div class="post-metadata">

**Author:** ![maschad](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/maschad/32/2710_2.png) [@maschad](https://forum.fuel.network/u/maschad)\
**Post date:** [October 31, 2024, 1:38pm UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949/3 "2024-10-31T13:38:05Z")

</div>

Hey @Antony , actually the first suggestion you made was correct. You can see an example of this in [`Adding Resources to a Transaction Request`](https://docs.fuel.network/docs/fuels-ts/transactions/transaction-request/#adding-resources-to-a-transaction-request)

```ts
// Instantiate the transaction request
const transactionRequest = new ScriptTransactionRequest({
  script: SumScript.bytecode,
});
 
const message: MessageCoin = {
  assetId: provider.getBaseAssetId(),
  sender: address,
  recipient: address,
  nonce: '0x',
  amount: bn(0),
  daHeight: bn(0),
};

// Adding message inputs
transactionRequest.addMessageInput(message);

```

---

<div class="post-metadata">

**Author:** ![Antony](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/antony/32/108_2.png) [@Antony](https://forum.fuel.network/u/Antony)\
**Post date:** [October 31, 2024, 1:44pm UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949/4 "2024-10-31T13:44:23Z")

</div>

Awesome, thanks for the reply and info @maschad !

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [November 21, 2024, 9:44am UTC](https://forum.fuel.network/t/how-to-add-a-message-input-to-transactionrequestlike/6949/5 "2024-11-21T09:44:37Z")

</div>

Closed on November 21, 2024, 9:44am UTC

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
