How can I make sendTransaction on predicate to work?

I’m trying to understand better how predicates can be used and saw this code example in the tests fuels-ts/predicate.test.ts at eda13d72c32f72652a34f926c4b9cf42ac36556c · FuelLabs/fuels-ts · GitHub
This does sendTransaction on a predicate, rather than transfer, which is what I’ve been playing with so far.

The issue is that I can’t make that snippet work in my code :smiling_face_with_tear:

This is where I’m trying to make it work predicate-practice-client1/App.tsx at predicate-sendtx · ewynx/predicate-practice-client1 · GitHub The thing that I changed is that the predicate is instantiated with the provider (testnet beta-3).
The initial error was "Invalid b256 (argument="b256", value="0x01", code=INVALID_ARGUMENT..".
Then I changed the id to a longer hex and now the error is "Invalid struct UtxoId. Field "outputIndex" not present. (argument="UtxoId", value"

Any suggestions on what I can change?

Hi Elena – I couldn’t replicate this issue. I cloned your repo and ran it as-is, only changing the private key to a valid one. You can try with my testnet test wallet:

const wallet = Wallet.fromPrivateKey("0x8618d4895db89ca7e455a6d302416fd2d4175372701c91c4313bd1c74fedf351", provider);

Everything seemed to have worked just fine:

Thanks for checking! Did you clone it to the branch predicate-sendtx? That’s where I have the example predicate-practice-client1/App.tsx at predicate-sendtx · ewynx/predicate-practice-client1 · GitHub

For clarity I also made this second repo where the issue can be found in the main branch: GitHub - ewynx/predicates-practice-client2

Also, it seems like the error that is caused by calling predicate.sendTransaction(request); comes from request.toTransactionBytes() which is done in sendTransaction. But I don’t know what to change to fix it.

1 Like

Hi @elena , so I was finding a few different validation issues with code you provided. This may happen when using test cases as your exemplary usage. Unit test cases, especially the one you were using as reference will use mocks to ensure we are only testing the functionality of a specific service or class, the Predicate class in this instance. And not the functionality of other services. However this will be done in end to end or feature level tests.

This meant the resource itself was being mocked in the test to make it available to the predicate, however this isn’t the case in your example repository. I have forked your repository and added exemplar usage of sendTransaction using a resource available to the instantiated predicate: Github - predicate sendTransaction example.

Additionally and maybe of interest, your predicate implementation in your previous forum post which makes use of the transfer functionality, will still call sendTransaction however it also prepares the resources and request, like your example above.

1 Like

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