# How to send money from predicate to owner back

**URL:** <https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639>\
**Category:** TypeScript SDK\
**Created:** [May 17, 2023, 8:51pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639 "2023-05-17T20:51:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sway](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sway/32/103_2.png) [@sway](https://forum.fuel.network/u/sway)\
**Post date:** [May 17, 2023, 8:51pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/1 "2023-05-17T20:51:42Z")

</div>

Have tried to make predicate.transfer to creator back as it was described in this [tutorial](https://fuellabs.github.io/fuels-ts/guide/predicates/predicates-with-configurable-constants.html#default-whitelist-address), but face `Error: not enough resources to fit the target`

code :

```auto
const configurableConstants = {
      ASSET0: token0,
      ASSET1: token1,
      PRICE: price.toFixed(0),
      MAKER: this.rootStore.accountStore.ethFormatWallet,
    };

const predicate = new Predicate(
  PREDICATE_BYTECODE,
  PREDICATE_ABI,
  this.rootStore.accountStore.provider,
  configurableConstants
);
const tx1 = await wallet.transfer(predicate.address, amount, token0);
console.log("tx1", tx1);
await tx1.waitForResult();

const tx2 = await predicate.transfer(wallet.address, amount, token0);
console.log("tx2", tx2);
await tx2.waitForResult();

```

link to predicate code - [here](https://github.com/compolabs/ethglobal-predicate/blob/master/src/main.sw)

Error message

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/8/89dc5fe99a2f32d636b54c240a042a12d629b261.png)

But also I realised that there is no signing from owner to cancel this predicate, so this transfer would be same if I just create Wallet instance from public address and make transfer . What am I doing wrong in this code example?

---

<div class="post-metadata">

**Author:** ![danielbate](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/danielbate/32/1617_2.png) [@danielbate](https://forum.fuel.network/u/danielbate)\
**Post date:** [May 18, 2023, 1:09pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/2 "2023-05-18T13:09:17Z")

</div>

Hi @sway , couple issues I can see:

1. The error could relate to either of the `transfer` calls, either the wallet does not have enough `token0` to fund the predicate, or the predicate doesn’t have enough `token0` at the time of evaluating the predicate. This is also dependent on the value of `amount` at the time both of those transactions are called. You can call `getBalance(token0)` on either the `wallet` or `predicate` instance to check the resources available prior to calling `transfer`.
2. The `configurableConstants` object in your TS code does not contain the same number of values as the configurable declared in your sway predicate, this will produce a validation error (different error to above).

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [May 18, 2023, 3:29pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/3 "2023-05-18T15:29:45Z")

</div>

I haven’t tried to run the code but it looks like when you do `predicate.transfer`, you’re trying to transfer all balance that the predicate has, but in that case there are no coins left to cover gas fees. When you call `predicate.transfer`, the only inputs of the transaction are the UTXOs owned by the predicate, so they should include coins to pay for the fee as well.

You can either try to transfer a slightly lower amount or build the transaction yourself and provide only one output of type `ChangeOutput` (instead of `CoinOutput`) - that way all predicate coins except fees will be transferred to the receiver and after the tx predicate won’t have any coins left.

---

<div class="post-metadata">

**Author:** ![sway](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sway/32/103_2.png) [@sway](https://forum.fuel.network/u/sway)\
**Post date:** [May 18, 2023, 4:30pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/4 "2023-05-18T16:30:01Z")

</div>

thanks for reply

abt passing not enough data as configurable by the time when I was creating this topic predicate code didn’t relay on MIN\_FULFILL\_AMOUNT0 , so lets assume that predicate doesn’t need MIN\_FULFILL\_AMOUNT0 , btw predicate creation was sucsesfull

and abt checking predicate balances like this

```auto
const configurableConstants = {
      ASSET0: token0,
      ASSET1: token1,
      PRICE: price.toFixed(0),
      MAKER: this.rootStore.accountStore.ethFormatWallet,
    };
    try {
      const predicate = new Predicate(
        PREDICATE_BYTECODE,
        PREDICATE_ABI,
        this.rootStore.accountStore.provider,
        configurableConstants
      );

      const initialPredicateBalance = await predicate.getBalance(token0);
      console.log("initialPredicateBalance", initialPredicateBalance);

      console.log("wallet.transfer", amount);
      const tx1 = await wallet.transfer(predicate.address, amount, token0);
      // console.log("tx1", tx1);
      await tx1.waitForResult();

      const feetx = await wallet.transfer(predicate.address, 50);
      await feetx.waitForResult();
      // console.log("feetx", feetx);

      const prediBalance = await predicate.getBalances();
      console.log("prediBalances", prediBalance);

      console.log("predicate.transfer", amount);
      const tx2 = await predicate.transfer(wallet.address, amount, token0);
      // console.log("tx2", tx2);
      await tx2.waitForResult();

      const finalPredicateBalance = await predicate.getBalance(token0);
      console.log("finalPredicateBalance", finalPredicateBalance);

      // if (tx.id != null)
      // this.notifyThatActionIsSuccessful("Order has bee placed", tx.id);
    } catch (e: unknown) {
      console.error(e);
    } finally {
      this.setLoading(false);
    }

```

after I added ETH transfer to predicate for gas error changed to this one

 ![image](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/b/b2b50bcfb0509277e3de0bb9eb0d623e27ce2811.png)

Assume that I need to send inputs/outputs for transfer call to pass this one, please check this one - [Predicates With Configurable Constants | Fuels-ts](https://fuellabs.github.io/fuels-ts/guide/predicates/predicates-with-configurable-constants.html#modifying-the-whitelist) (seems to be wrong)

---

<div class="post-metadata">

**Author:** ![sway](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/sway/32/103_2.png) [@sway](https://forum.fuel.network/u/sway)\
**Post date:** [May 18, 2023, 4:30pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/5 "2023-05-18T16:30:40Z")

</div>

good idea! added ETH transfer to pay gas fee and error changed, check it in message above

---

<div class="post-metadata">

**Author:** ![mpoplavkov](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/mpoplavkov/32/399_2.png) [@mpoplavkov](https://forum.fuel.network/u/mpoplavkov)\
**Post date:** [May 18, 2023, 6:35pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/6 "2023-05-18T18:35:56Z")

</div>

As I see it, the error basically says that the predicate returned false. You can try it out with a more simple predicate like the one that always returns true and then add new checks step by step. It’s a pain that right now you can’t debug predicates in other way

---

<div class="post-metadata">

**Author:** ![Torres-ssf](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/torres-ssf/32/1380_2.png) [@Torres-ssf](https://forum.fuel.network/u/Torres-ssf)\
**Post date:** [May 19, 2023, 3:24pm UTC](https://forum.fuel.network/t/how-to-send-money-from-predicate-to-owner-back/2639/7 "2023-05-19T15:24:29Z")

</div>

@sway thanks for bringing that up.

For your first question, it seems like the error is happening because the predicate is trying to transfer all locked funds, leaving nothing for the transaction fees. I’m actually in the process of revising a doc page on how to send and spend funds from a predicate, so your input is valuable. I’ll make sure to add this info to the doc page.

For the second issue, this is happening because the predicate is returning false. If that wasn’t supposed to happen I’ll need to take a look at your predicate code and your use case. Could you share more details? I’m keen to help figure out what’s going on.

Thanks!
