# Cannot deploy contract on beta-5 using ts sdk

**URL:** <https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473>\
**Category:** TypeScript SDK\
**Created:** [February 26, 2024, 7:07pm UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473 "2024-02-26T19:07:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsociety](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fsociety/32/508_2.png) [@fsociety](https://forum.fuel.network/u/fsociety)\
**Post date:** [February 26, 2024, 7:07pm UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473/1 "2024-02-26T19:07:10Z")

</div>

TS sdk version: 0.73.0

Here are the toolchain versions:

**forc** : 0.49.1

- **forc-client**
- **forc-deploy** : 0.49.1
- **forc-run** : 0.49.1
- **forc-crypto** : 0.49.1
- **forc-doc** : 0.49.1
- **forc-explore** : 0.28.1
- **forc-fmt** : 0.49.1
- **forc-lsp** : 0.49.1
- **forc-tx** : 0.49.1
- **forc-wallet** : 0.4.2  
**fuel-core** : 0.22.0  
**fuel-core-keygen** : 0.22.0  
**fuels versions**  
**forc** : 0.54.0  
**forc-wallet** : 0.54.0

Here is the code snippet:

```auto
const exchangeBytecode = readFileSync(path.join(__dirname, '../../bin-files/thunder_exchange.bin'));
const exchangeFactory = new ContractFactory(exchangeBytecode, ThunderExchangeAbi__factory.abi, OWNER);
const { minGasPrice: gasPrice } = provider.getGasConfig();
const exchange = await exchangeFactory.deployContract({gasPrice});

```

Here is the error I receive when I try to deploy the contract:

```auto
_FuelError: Invalid u16, too many bytes.
    at NumberCoder.encode (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/abi-coder/src/coders/number.ts:55:13)
    at WitnessCoder.encode (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/transactions/src/coders/witness.ts:26:39)
    at /Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/abi-coder/src/coders/array.ts:34:74
    at Array.map (<anonymous>)
    at ArrayCoder.encode (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/abi-coder/src/coders/array.ts:34:52)
    at TransactionCreateCoder.encode (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/transactions/src/coders/transaction.ts:220:73)
    at TransactionCoder.encode (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/transactions/src/coders/transaction.ts:372:40)
    at CreateTransactionRequest.toTransactionBytes (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/providers/src/transaction-request/transaction-request.ts:189:35)
    at CreateTransactionRequest.byteSize (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/providers/src/transaction-request/transaction-request.ts:518:17)
    at CreateTransactionRequest.calculateMinGas (/Users/fsociety/thunder/thunder-sdk/node_modules/@fuel-ts/providers/src/transaction-request/transaction-request.ts:538:25) {
  VERSIONS: { FORC: '0.49.2', FUEL_CORE: '0.22.0', FUELS: '0.73.0' },
  code: 'encode-error'
}

```

---

<div class="post-metadata">

**Author:** ![anderson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/anderson/32/320_2.png) [@anderson](https://forum.fuel.network/u/anderson)\
**Post date:** [February 26, 2024, 8:30pm UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473/2 "2024-02-26T20:30:29Z")

</div>

I think the [latest release](https://github.com/FuelLabs/fuels-ts/releases/tag/v0.75.0) includes [the fix for your problem](https://github.com/FuelLabs/fuels-ts/issues/1785). 🙂

Updating to the new version should do the trick.

Please, let me know how it goes.

Thanks.

---

<div class="post-metadata">

**Author:** ![anderson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/anderson/32/320_2.png) [@anderson](https://forum.fuel.network/u/anderson)\
**Post date:** [February 26, 2024, 8:36pm UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473/3 "2024-02-26T20:36:03Z")

</div>

For more information about this problem, please refer to this post:

> [@FuelError: Invalid u16, too many bytes](https://forum.fuel.network/t/fuelerror-invalid-u16-too-many-bytes/4362/6):
>
> delved deeper into what might be causing the error, and I think I’ve got it. In the [encode method](https://github.com/FuelLabs/fuels-ts/blob/59432a665f44811469665cd469e9f8f2366570f3/packages/abi-coder/src/coders/v0/number.ts#L54), some value is being encoded. Turns out, one of the values being encoded is the size of the compiled bytecode. When this bytecode size exceeds 65535 (max value of u16), the byte length size of the value is 3 and the invariant fails. Now somewhere when encoding this value, the baseType has been set to u16, so the max size of a contract (at least according to the encoder) is max(u16). Is this a bug, …

---

<div class="post-metadata">

**Author:** ![fsociety](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fsociety/32/508_2.png) [@fsociety](https://forum.fuel.network/u/fsociety)\
**Post date:** [February 28, 2024, 10:31am UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473/4 "2024-02-28T10:31:34Z")

</div>

Yes! It solved my problem

Thanks a lot!

---

<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:** [March 20, 2024, 6:31am UTC](https://forum.fuel.network/t/cannot-deploy-contract-on-beta-5-using-ts-sdk/4473/5 "2024-03-20T06:31:57Z")

</div>

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