Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytecode to factory outputted by typegen #2707

Closed
nedsalk opened this issue Jul 5, 2024 · 3 comments · Fixed by #2824
Closed

Add bytecode to factory outputted by typegen #2707

nedsalk opened this issue Jul 5, 2024 · 3 comments · Fixed by #2824
Assignees
Labels
feat Issue is a feature

Comments

@nedsalk
Copy link
Contributor

nedsalk commented Jul 5, 2024

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.

@arboleya
Copy link
Member

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

@nedsalk
Copy link
Contributor Author

nedsalk commented Jul 20, 2024

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.

@arboleya
Copy link
Member

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,
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants