FuelError: Only one field must be provided

I get the Only one field must be provided error when building with on top of the sway-applications. It happens when building the UI for the english-auction, when interacting with the create auction contract.

Code snippet:

const createAuction = async (
  multisigContract: AuctionContractAbi,
  bid_asset: AssetId,
  duration: BigNumberish,
  initial_price: BigNumberish,
  reserve_price: Option<BigNumberish>,
  seller: IdentityInput,
) => {
  try {
    const txResponse = await multisigContract.functions
    .create(
      bid_asset,
      10,
      1,
      0,
      seller
    )
    .callParams({
	  forward: [10, BaseAssetId],
	  gasLimit: 1,
	})
    .txParams({
      gasPrice: 1,
      gasLimit: 100_000,
    })
    .call();
    console.log('Auction created successfully', txResponse);
  } catch (error) {
  console.error('Failed to create auction:', error);
  }
}
1 Like

Error:

bundle.js:336 Failed to create auction: FuelError: Only one field must be provided.
    at EnumCoder.encode (enum.ts:66:1)
    at tuple.ts:39:1
    at Array.map (<anonymous>)
    at TupleCoder.encode (tuple.ts:37:1)
    at FunctionFragment.encodeArguments (function-fragment.ts:121:1)
    at createContractCall (base-invocation-scope.ts:31:1)
    at base-invocation-scope.ts:86:1
    at Array.map (<anonymous>)
    at get calls (base-invocation-scope.ts:86:1)
    at FunctionInvocationScope.updateContractInputAndOutput (base-invocation-scope.ts:104:1)
1 Like

Hi @poppyseedDev,

So this is being thrown at encodeArguments, meaning that one of the parameters we are passing to create is being passed incorrectly. From the error we can also see it’s being thrown by the EnumCoder, so it must be thrown by a parameter expecting an enum value. From the ABI I can see that the seller parameter is the only one expecting an enum so the problem must be there.

Where you are building the seller parameter I can see you are passing two fields, and as the error explains, there should only be one. So:

    const seller: IdentityInput = { 
      Address: {
        value: wallet.address.toString(),
      },
      ContractId: {
        value: CONTRACT_ID,
      },
    };

should be

    const seller: IdentityInput = { 
      Address: {
        value: wallet.address.toB256(),
      },
    };

OR

    const seller: IdentityInput = { 
     ContractId: {
        value: CONTRACT_ID,
      },
    };

Please note, for address I’ve also used the toB256() function over toString() as we are expecting a b256 address here. toString() would give us bech32.

1 Like

Hey, I fixed the values as mentioned however I still get the same exact error:


const createAuction = async (
  multisigContract: AuctionContractAbi,
  bid_asset: AssetId,
  duration: BigNumberish,
  initial_price: BigNumberish,
  reserve_price: Option<BigNumberish>,
  seller: IdentityInput,
) => {
  try {
    const txResponse = await multisigContract.functions
    .create(
      bid_asset,
      duration,
      initial_price,
      reserve_price,
      seller
    )
    .callParams({
	  forward: [10, BaseAssetId],
	  gasLimit: 1,
	})
    .txParams({
      gasPrice: 1,
      gasLimit: 100_000,
    })
    .call();
    console.log('Auction created successfully', txResponse);
  } catch (error) {
  console.error('Failed to create auction:', error);
  }
}
  const handleCreateAuction = async () => {
    if (!contract || !wallet) {
      alert("Contract not loaded or wallet not connected");
      return;
    }
    
    let bid_asset: AssetIdInput = {
      value: BaseAssetId,
    };

    const duration: BigNumberish = 10; 
    const initial_price: BigNumberish = 1; 
    const reserve_price: BigNumberish = 10; 
    const seller: IdentityInput = { 
      Address: {
        value: wallet.address.toB256(),
      },
      ContractId: {
        value: CONTRACT_ID,
      },
    };
    if (contract && wallet) {
      await createAuction(
        contract, 
        bid_asset, 
        duration, 
        initial_price, 
        reserve_price, 
        seller
      );
    }
  };

I can still see in your code that seller has 2 keys, Address AND ContractId. You must only use one, as the error states. Address OR ContractId. For example, please change seller to:

    const seller: IdentityInput = { 
      Address: {
        value: wallet.address.toB256(),
      },
    };

Please note I have run your code successfully with the above, I can push a PR if that is preferred.

2 Likes

I got the same error and was able to resolve by adjusting some Address type values.