String decode problem

Libraries versions
forc → 0.49.3
fuels → 0.79.0

I trying to get the name and symbol in my NFT Contract, this methods returns a String.

In ts sdk

Console error:

/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+abi-coder@0.79.0/node_modules/@fuel-ts/abi-coder/src/encoding/coders/v0/StdStringCoder.ts:63
      throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid std string byte data size.`);
            ^
_FuelError: Invalid std string byte data size.
    at StdStringCoder.decode (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+abi-coder@0.79.0/node_modules/@fuel-ts/abi-coder/src/encoding/coders/v0/StdStringCoder.ts:63:13)
    at OptionCoder.decode (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+abi-coder@0.79.0/node_modules/@fuel-ts/abi-coder/src/encoding/coders/v0/EnumCoder.ts:101:39)
    at OptionCoder.decode (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+abi-coder@0.79.0/node_modules/@fuel-ts/abi-coder/src/encoding/coders/v0/OptionCoder.ts:31:40)
    at FunctionFragment.decodeOutput (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+abi-coder@0.79.0/node_modules/@fuel-ts/abi-coder/src/FunctionFragment.ts:211:18)
    at /dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+program@0.79.0_dexie@4.0.4/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:108:19
    at Array.map (<anonymous>)
    at FunctionInvocationResult.getDecodedValue (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+program@0.79.0_dexie@4.0.4/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:106:41)
    at new InvocationResult (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+program@0.79.0_dexie@4.0.4/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:60:23)
    at new FunctionInvocationResult (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+program@0.79.0_dexie@4.0.4/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:163:5)
    at Function.build (/dev/sandbox/test-metadata/node_modules/.pnpm/@fuel-ts+program@0.79.0_dexie@4.0.4/node_modules/@fuel-ts/program/src/functions/invocation-results.ts:187:22) {
  VERSIONS: { FORC: '0.49.3', FUEL_CORE: '0.22.1', FUELS: '0.79.0' },
  code: 'decode-error'
}

The OptionCoder trying to decode a StdString but the String is provided.

2 Likes

Hey @luisburigo really appreciate you bringing up the issue. Our typescript SDK team is looking into it. :saluting_face:

2 Likes

Hey @luisburigo,

I can see from the error stack that you are using v0 encoding. Unfortunately nested heap types (String in Option in your case) is unsupported under v0.

Fortunately, we have v1 being released imminently which does support nested heaps, so sit tight!

If you want a quicker fix for this, I’d recommend converting the String to a fixed length string using __to_str_array and your return type will need to be Option<str[n]>;

But I really would recommend waiting for v1, it comes with lots of encoding improvements.

3 Likes

This was included in fuels@0.83.0. Be sure to also build your project with forc@0.56.0.

2 Likes

Hey @danielbate, thanks for the update on the versions.

Could you also share which version of fuel-core is compatible with this release? I tried to run pnpm fuels deploy, but I’m not sure if the version of fuel-core on my machine is the correct one.

Error:

Error: Unknown field "version" on type "ConsensusParameters".: 
{
  "response": {
    "data": null,
    "errors": [
      {
        "message": "Unknown field \"version\" on type \"ConsensusParameters\".",
        "locations": [
          {
            "line": 30,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"TxParameters\".",
        "locations": [
          {
            "line": 54,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"ScriptParameters\".",
        "locations": [
          {
            "line": 71,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"FeeParameters\".",
        "locations": [
          {
            "line": 83,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"ContractParameters\".",
        "locations": [
          {
            "line": 77,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"PredicateParameters\".",
        "locations": [
          {
            "line": 63,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"height\" on type \"Block\".",
        "locations": [
          {
            "line": 20,
            "column": 3
          }
        ]
      },
      {
        "message": "Unknown field \"version\" on type \"GasCosts\".",
        "locations": [
          {
            "line": 89,
            "column": 3
          }
        ]
      },
      {
        "message": "Field \"croo\" must not have a selection since type \"U64\" has no subfields",
        "locations": [
          {
            "line": 184,
            "column": 3
          }
        ]
      },
      {
        "message": "Fragment \"DependentCostFragment\" cannot be spread here as objects of type \"U64\" can never be of type \"DependentCost\"",
        "locations": [
          {
            "line": 185,
            "column": 5
          }
        ]
      }
    ],
    "status": 200,
    "headers": {}
  },
  "request": {
    "query": "query getChain {\n  chain {\n    ...chainInfoFragment\n  }\n}\n\nfragment chainInfoFragment on ChainInfo {\n  name\n  latestBlock {\n    ...blockFragment\n  }\n  daHeight\n  consensusParameters {\n    ...consensusParametersFragment\n  }\n}\n\nfragment blockFragment on Block {\n  id\n  height\n  header {\n    time\n  }\n  transactions {\n    id\n  }\n}\n\nfragment consensusParametersFragment on ConsensusParameters {\n  version\n  txParams {\n    ...TxParametersFragment\n  }\n  predicateParams {\n    ...PredicateParametersFragment\n  }\n  scriptParams {\n    ...ScriptParametersFragment\n  }\n  contractParams {\n    ...ContractParametersFragment\n  }\n  feeParams {\n    ...FeeParametersFragment\n  }\n  gasCosts {\n    ...GasCostsFragment\n  }\n  baseAssetId\n  chainId\n}\n\nfragment TxParametersFragment on TxParameters {\n  version\n  maxInputs\n  maxOutputs\n  maxWitnesses\n  maxGasPerTx\n  maxSize\n}\n\nfragment PredicateParametersFragment on PredicateParameters {\n  version\n  maxPredicateLength\n  maxPredicateDataLength\n  maxGasPerPredicate\n  maxMessageDataLength\n}\n\nfragment ScriptParametersFragment on ScriptParameters {\n  version\n  maxScriptLength\n  maxScriptDataLength\n}\n\nfragment ContractParametersFragment on ContractParameters {\n  version\n  contractMaxSize\n  maxStorageSlots\n}\n\nfragment FeeParametersFragment on FeeParameters {\n  version\n  gasPriceFactor\n  gasPerByte\n}\n\nfragment GasCostsFragment on GasCosts {\n  version\n  add\n  addi\n  aloc\n  and\n  andi\n  bal\n  bhei\n  bhsh\n  burn\n  cb\n  cfei\n  cfsi\n  div\n  divi\n  ecr1\n  eck1\n  ed19\n  eq\n  exp\n  expi\n  flag\n  gm\n  gt\n  gtf\n  ji\n  jmp\n  jne\n  jnei\n  jnzi\n  jmpf\n  jmpb\n  jnzf\n  jnzb\n  jnef\n  jneb\n  lb\n  log\n  lt\n  lw\n  mint\n  mlog\n  modOp\n  modi\n  moveOp\n  movi\n  mroo\n  mul\n  muli\n  mldv\n  noop\n  not\n  or\n  ori\n  poph\n  popl\n  pshh\n  pshl\n  ret\n  rvrt\n  sb\n  sll\n  slli\n  srl\n  srli\n  srw\n  sub\n  subi\n  sw\n  sww\n  time\n  tr\n  tro\n  wdcm\n  wqcm\n  wdop\n  wqop\n  wdml\n  wqml\n  wddv\n  wqdv\n  wdmd\n  wqmd\n  wdam\n  wqam\n  wdmm\n  wqmm\n  xor\n  xori\n  call {\n    ...DependentCostFragment\n  }\n  ccp {\n    ...DependentCostFragment\n  }\n  croo {\n    ...DependentCostFragment\n  }\n  csiz {\n    ...DependentCostFragment\n  }\n  k256 {\n    ...DependentCostFragment\n  }\n  ldc {\n    ...DependentCostFragment\n  }\n  logd {\n    ...DependentCostFragment\n  }\n  mcl {\n    ...DependentCostFragment\n  }\n  mcli {\n    ...DependentCostFragment\n  }\n  mcp {\n    ...DependentCostFragment\n  }\n  mcpi {\n    ...DependentCostFragment\n  }\n  meq {\n    ...DependentCostFragment\n  }\n  retd {\n    ...DependentCostFragment\n  }\n  s256 {\n    ...DependentCostFragment\n  }\n  scwq {\n    ...DependentCostFragment\n  }\n  smo {\n    ...DependentCostFragment\n  }\n  srwq {\n    ...DependentCostFragment\n  }\n  swwq {\n    ...DependentCostFragment\n  }\n  contractRoot {\n    ...DependentCostFragment\n  }\n  stateRoot {\n    ...DependentCostFragment\n  }\n  vmInitialization {\n    ...DependentCostFragment\n  }\n  newStoragePerByte\n}\n\nfragment DependentCostFragment on DependentCost {\n  __typename\n  ... on LightOperation {\n    base\n    unitsPerGas\n  }\n  ... on HeavyOperation {\n    base\n    gasPerUnit\n  }\n}"
  }
}

Using the fuel-toolchain.toml with:

[toolchain]
channel = "nightly-2024-04-12"

[components]
forc = "0.56.0"

And fuel-core in docker:

FROM ghcr.io/fuellabs/fuel-core:v0.22.1

Hey @luisburigo :wave:

You can find the compatible versions for the 0.83.0 release in the release notes.

In your case, you will need fuel-core@0.24.3 and forc@0.56.0.

Hope that helps :slight_smile:

2 Likes