Hi All,
In typescript and working with the FuelConnector, one of the parameters the FuelConnector sendTransaction()
function takes is a TransactionRequestLike.
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?
// 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
/**
* 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);
}
}