fuels-ts icon indicating copy to clipboard operation
fuels-ts copied to clipboard

Add `bytecode` to factory outputted by `typegen`

Open nedsalk opened this issue 1 year ago • 3 comments

We are currently outputting the bytecode of a contract in a separate file, which forces people to do two imports:

import { CallTestContractAbi__factory } from '../test/typegen/contracts';
import bytecode from '../test/typegen/contracts/CallTestContractAbi.hex';

By putting the bytecode on the factory and integrating it with the factory properly, this can be reduced to only one import:

import { CallTestContractAbi__factory } from '../test/typegen/contracts';

[!TIP] To maintain backwards compatibility and not make this a breaking change, we can continue exporting the file separately.

nedsalk avatar Jul 05 '24 16:07 nedsalk

Wouldn't this include the bytecode in the final bundle regardless of being in use?

arboleya avatar Jul 19 '24 20:07 arboleya

Wouldn't this include the bytecode in the final bundle regardless of being in use?

If the factory is not in use then I believe it'll be treeshaken.

nedsalk avatar Jul 20 '24 09:07 nedsalk

I think it must be at least in a separate file:

import { Counter, deployCounter } from './typegend';

Pseudo code:

import { Account, DeployContractOptions, DeployContractResult, ContractFactory } from 'fuels';
import { Counter, abi, storageSlots } from './Counter'

export const counterBytecode = '0x1af03..';

export async function deployCounter(
  wallet: Account,
  options: DeployContractOptions = {}
): Promise<DeployContractResult<Counter>> {
  const factory = new ContractFactory(counterBytecode, abi, wallet);

  return factory.deployContract<Counter>({
    storageSlots,
    ...options,
  });
}

arboleya avatar Jul 20 '24 15:07 arboleya