# Unexpected behavior when callings scripts

**URL:** <https://forum.fuel.network/t/unexpected-behavior-when-callings-scripts/2675>\
**Category:** TypeScript SDK\
**Created:** [May 24, 2023, 8:18am UTC](https://forum.fuel.network/t/unexpected-behavior-when-callings-scripts/2675 "2023-05-24T08:18:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maurice](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@maurice](https://forum.fuel.network/u/maurice)\
**Post date:** [May 24, 2023, 8:18am UTC](https://forum.fuel.network/t/unexpected-behavior-when-callings-scripts/2675/1 "2023-05-24T08:18:19Z")

</div>

Hey guys, now that I can call a script, I get multiple unexpected behavior. Thus, I reduced my complex script to a simple script to test. Assume my wallet on the TS SDK side is funded by more than enough tokens. My simple script looks like this:

```auto
fn main(
    some_contract: ContractId,
) {
    transfer(1_000_000, BASE_ASSET_ID, Identity::ContractId(some_contract));
}

```

My script call looks like this (in the TS SDK):

```auto
const scriptInstance = new Script<ContractIdInput[], any>(scriptBin, simpleScriptAbi, wallet);
const value = await scriptInstance.functions
        .main({ value: someContract.id.toHexString() })
        .txParams({ gasPrice: 1 })
        .addContracts([
            {
                id: someContract.id,
                account: someContract.account,
                interface: {
                    encodeFunctionData: someContract.interface.decodeFunctionData,
                    decodeFunctionResult: someContract.interface.decodeFunctionResult,
                    updateExternalLoggedTypes: someContract.interface.updateExternalLoggedTypes,
                    loggedTypes: someContract.interface.loggedTypes,
                },
                provider: someContract.provider,
            },
        ])
        .call();

```

It just transfers an amount of the BASE\_ASSET\_ID to my contract `some_contract` . This works and I can prove that the BASE\_ASSET\_ID flows from my wallet to the contract by querying the balances on the TS SDK side. Now comes the trouble. As soon as I want to transfer my own token instead of the BASE\_ASSET\_ID, the script receipt says “NotEnoughBalance”. **Again, I can prove that there is enough balance. What can be the reason?** Another weird thing is that I cannot query the balance of my contract inside my script. If instead of calling the transfer function, I call the stdlib `balance_of` function and give it my contract id and `BASE_ASSET_ID` , the script receipt says `ContractNotInInputs` . I was not aware, that the base asset even has a contract that I could put into the inputs??? Any answer would be very welcome, this is completely blocking our development.

---

<div class="post-metadata">

**Author:** ![maurice](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@maurice](https://forum.fuel.network/u/maurice)\
**Post date:** [May 24, 2023, 8:25am UTC](https://forum.fuel.network/t/unexpected-behavior-when-callings-scripts/2675/2 "2023-05-24T08:25:13Z")

</div>

Oh in case somebody wonders why I would add `.addContracts()` when calling the script even though I don’t use the contract abi inside the script… well, I don’t know why it’s required but if I don’t add it in the call, I get a `ContractNotInInputs` script panic.

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/david/32/32_2.png) [@david](https://forum.fuel.network/u/david)\
**Post date:** [May 24, 2023, 10:33am UTC](https://forum.fuel.network/t/unexpected-behavior-when-callings-scripts/2675/3 "2023-05-24T10:33:33Z")

</div>

When running a script, you need to manually collect the UTXOs you want the script to have access to, and pass those UTXOs to the script when it’s called.

You can see the code for gathering UTXOs in the AMM example:

> <https://github.com/FuelLabs/sway-applications/blob/master/AMM/project/test-utils/src/setup.rs#L287-L317>

Although this is written in Rust, so something similar would have to be done in TypeScript.

Regarding calling `.addContract()`, you need to append a contract UTXO to a transaction in order to have access to that contract’s balance, even if you’re not directly calling the contract.
