Error: Invalid u16, too many bytes

We’ve found some strange issues when trying to deploy our contract from the frontend. The contract compiles without any problems, and the bytecode size is 74,640 bytes, which is well within the 100kB limit.

If we use the command-line interface (CLI) and run forc deploy --testnet, the deployment works as expected.

However, when we try to deploy the contract programmatically from the frontend using the auto-generated ABI and hex files, we encounter a vague error that doesn’t provide any useful information.

To generate the contract types, we followed the steps from the Fuel documentation:

npx fuels init --contracts ../counter-contract/ --output ./src/sway-api
npx fuels build

When we try to deploy the contract using the generated types:

import { FuelMultisigAbi__factory } from "@/services/contracts/multisig/contracts/factories/FuelMultisigAbi__factory";
const gasPrice = wallet.provider.getGasConfig().minGasPrice;
const gasMax = wallet.provider.getGasConfig().maxGasPerTx;
const factory = await FuelMultisigAbi__factory.deployContract(
    maxFee: gasMax,

The deployment fails with a vague error.

  at new t....


  at new JSONRPCErrorException ...

However, if we change the contract to a simple counter contract, the deployment works smoothly. This suggests that the issue is specific to the contract we’re trying to deploy.

Also, when we use the TypeGen process from the Fuels TS guide:

pnpm fuels typegen -i ./abis/*-abi.json -o ./types

And then deploy it:

import { DemoContractAbi__factory } from './types';
import bytecode from './types/DemoContractAbi.hex';

const gasPrice = wallet.provider.getGasConfig().minGasPrice;
// Deploy
const contract = await DemoContractAbi__factory.deployContract(bytecode, wallet, { gasPrice });

This deployment still fails.

If we try to replicate this using Fuelet wallet instead of the Fuel wallet, we see the following error:

Error: FuelError: Invalid u16, too many bytes.
    at new JSONRPCErrorException (models.js:60:28)
    at JSONRPCClient.eval (client.js:217:48)
    at step (client.js:107:23)
    at Object.eval [as next] (client.js:48:20)
    at fulfilled (client.js:11:32)

The dependencies involved are:

    "@fuels/connectors": "0.1.1",
    "@fuels/react": "0.18.0",
    "fuels": "0.82.0",

It seems to be an issue similar to the one on this forum post:

This bug is somewhat blocking for our development at the moment. The inability to reliably deploy our full-featured contract is hindering our ability to thoroughly test the contract’s functionality. To work around this, we have created a temporary contract with a reduced set of features, in an effort to keep the contract size smaller. However, this workaround means we won’t be able to fully test the complete functionality of our intended contract until we can resolve the deployment issue. This is a suboptimal situation, as we won’t have complete confidence in the contract’s behavior until we can deploy and test the full version. Resolving this deployment problem is a high priority for us, as it is currently impeding our development progress.

1 Like

Hey @Luca, sorry to hear you’ve been having problems. Are you able to share the contract/repository with me? Could you also let me know what forc and fuel-core versions you are running. And what encoding the contract is using (encoding property in the ABI).

1 Like

Hi Daniel!
Contract repo:

Frontend repo:

latest-aarch64-apple-darwin (default)
  forc : 0.49.3
    - forc-client
      - forc-deploy : 0.49.3
      - forc-run : 0.49.3
    - forc-crypto : 0.49.3
    - forc-doc : 0.49.3
    - forc-explore : 0.28.1
    - forc-fmt : 0.49.3
    - forc-lsp : 0.49.3
    - forc-tx : 0.49.3
    - forc-wallet : 0.4.3
  fuel-core : 0.22.4
  fuel-core-keygen : 0.22.4
1 Like

Okay so I have been able to deploy your contract to a local testnet running fuels@0.82.0 / forc@0.49.3 and fuel-core@0.22.4 (fuelup on latest toolchain). I suspect this is a versioning issue.

Firstly, I built the contract using forc build --release. This will build the project using the forc binaries installed via fuelup, so 0.49.3. Please note this works differently than npx fuels build which will build the project using the binaries that we couple with your fuels version. My concern is that if you are not specifying the version, it may be fetching the latest version of fuels (0.83.0) which has encoding changes that are not compatible with the current testnet. Therefore we would actually be compiling a u16 with a different amount of bytes, hence the error. Could you validate this with npx fuels@0.82.0 build?

However, then I can run typegen and create types for the ABI and bytecode I generated with forc build --release, with pnpm fuels typegen -i ../multisig-contract/out/release/*-abi.json -o ./sway-api.

And then successfully deploy the contract and call a contract function:

import { FuelMultisigAbi__factory } from '../sway-api';
import multiSigBytecode from '../sway-api/FuelMultisigAbi.hex'

const contract = await FuelMultisigAbi__factory.deployContract(multiSigBytecode, wallet);
const { value } = await contract.functions.get_owners().call();
 // []

So apologies I haven’t got to the bottom of your problem but when following a single flow it does succeed. I’d recommend either working fully with the fuels CLI but be sure to specify the version, which I did also get a successful deploy with but used pnpm fuels build rather than npx to ensure I was using the locally installed fuels version. Or use forc build and typegen.

We also have a new version of the testnet coming soon that has the new encoding supported on the latest version of fuels, which I also suspect would resolve this.


After replicating the approach you described, we encountered the same issue. We created a simplified repository to investigate further, and it exhibited the same error.

The repository is available at Link, and the relevant branch is [test/contract-deployment].

We’ve included a Makefile to streamline the setup process. Once the wallet is connected, if you’re using the Fuel wallet and click the “Deploy” button, it will start loading but eventually fail with an unclear error in the console. If you’re using the Fuelet wallet, it prompts you to approve the transaction but indicates that the deployment will fail. After approving the transaction, check the console, where you’ll see the deployment failure and the following error message: Error: Invalid u16, too many bytes.

1 Like

Really appreciate the exemplary repo!

Would you also mind committing the built ABI? I’d like to check the encoding you are using.

1 Like

I’ve just pushed the compiled contract. You have there both debug and release versions

Hey Luca :wave:

Thank you for you patience on this matter.

From what I can see, it does not appear to be caused by the version that @danielbate was implying.

I successfully managed to deploy to the Beta 5 network with the contract you supplied - however, only with the Fuel Development Wallet. I too experienced similar issues when attempting to deploy with the Fuel Wallet and Fuelet.

Could you possibly try this approach and let us know the outcomes?


Hey! We have tried that approach and it seems to work. Should we just use the Development Wallet and wait for new releases of the other two?

That’s great news!

I’d advise to proceed with the Development Wallet while developing you dApp, as it has better functionality for debugging and testing purposes.

I have just recently deployed your contract successfully, using Fuel Wallet (v0.16.6), so potentially this was an issue with a previous version.

Hope this helps :slight_smile:

1 Like