FuelLabs/fuels-ts · error · FuelError
MISSING_PROVIDER
MISSING_PROVIDER
Error message
Cannot create transaction request without provider
What it means
Thrown by ContractFactory.createTransactionRequest() (packages/contract/src/contract-factory.ts:146) when this.provider is null/undefined. A provider is required to compute the contract ID and assemble the CreateTransactionRequest with correct chain parameters. The provider is set during construction: if the third argument to new ContractFactory() is null, or is an object that does not expose a 'provider' property, this.provider stays null.
Source
Thrown at packages/contract/src/contract-factory.ts:146
*/
createTransactionRequest(deployOptions?: DeployContractOptions & { bytecode?: BytesLike }) {
const storageSlots = (deployOptions?.storageSlots ?? [])
.concat(this.storageSlots)
.map(({ key, value }) => ({
key: hexlifyWithPrefix(key),
value: hexlifyWithPrefix(value),
}))
.filter((el, index, self) => self.findIndex((s) => s.key === el.key) === index)
.sort(({ key: keyA }, { key: keyB }) => keyA.localeCompare(keyB));
const options = {
salt: randomBytes(32),
...(deployOptions ?? {}),
storageSlots,
};
if (!this.provider) {
throw new FuelError(
ErrorCode.MISSING_PROVIDER,
'Cannot create transaction request without provider'
);
}
if (deployOptions?.configurableConstants) {
this.setConfigurableConstants(deployOptions.configurableConstants);
}
const bytecode = deployOptions?.bytecode || this.bytecode;
const stateRoot = options.stateRoot || getContractStorageRoot(options.storageSlots);
const contractId = getContractId(bytecode, options.salt, stateRoot);
const transactionRequest = new CreateTransactionRequest({
bytecodeWitnessIndex: 0,
witnesses: [bytecode],
...options,
});
transactionRequest.addContractCreatedOutput(contractId, stateRoot);View on GitHub (pinned to b3f37c91ac)
Solutions
- Pass an Account (Wallet) or Provider as the third argument to new ContractFactory(bytecode, abi, accountOrProvider).
- Call factory.connect(provider) to obtain a new factory instance bound to a provider.
- If using deploy methods, ensure the factory was constructed with a connected Wallet/Account, not just a raw provider for read-only access.
Example fix
// before const factory = new ContractFactory(bytecode, abi); await factory.deploy(); // after const factory = new ContractFactory(bytecode, abi, wallet); await factory.deploy();
Defensive patterns
Strategy: validation
Validate before calling
const factory = new ContractFactory(bytecode, abi);
if (!factory.provider) {
throw new Error('ContractFactory has no provider. Pass a Provider or Account as the 3rd argument.');
}
const { transactionRequest } = factory.createTransactionRequest(); Type guard
function hasProvider(factory: ContractFactory): factory is ContractFactory & { provider: Provider } {
return factory.provider !== null && factory.provider !== undefined;
} Try / catch
try {
const { transactionRequest } = factory.createTransactionRequest();
} catch (e) {
if (e instanceof FuelError && e.code === 'missing-provider') {
// re-create factory with provider/account
const factoryWithProvider = new ContractFactory(bytecode, abi, wallet);
}
throw e;
} Prevention
- Always pass an Account/Wallet or Provider as the third argument to new ContractFactory().
- Use factory.connect(provider) to create a provider-bound copy if the factory was initially created without one.
- Check factory.provider before calling deploy or createTransactionRequest in code paths where the provider may be absent.
When it happens
Trigger: Constructing a ContractFactory without a provider/account (third constructor argument omitted or null), then calling createTransactionRequest(), deploy(), deployAsCreateTx(), or deployAsBlobTx(). Also triggered if a non-Account, non-Provider object is passed as the third argument (it is treated as a Provider and assigned directly but may be null).
Common situations: Building a ContractFactory from bytecode and ABI for later use (e.g. in tests or scripts) without immediately connecting a provider; forgetting to pass the wallet/provider; refactoring code that previously passed the provider separately.
Related errors
- ACCOUNT_REQUIRED
- INVALID_CHUNK_SIZE_MULTIPLIER
- CONTRACT_SIZE_EXCEEDS_LIMIT
- FUNDS_TOO_LOW
- TRANSACTION_FAILED
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/1e3a77fcab9d89dc.
Report an issue: GitHub.