soroban-cli icon indicating copy to clipboard operation
soroban-cli copied to clipboard

ts bindings: Failure when converting function return value

Open vinamogit opened this issue 1 year ago • 0 comments
trafficstars

What version are you using?

soroban --version soroban 20.0.0-rc4 (bce5e56ba16ba977200b022c91f3eaf6282f47eb) soroban-env 20.0.0-rc2 (8c63bff68a15d79aca3a705ee6916a68db57b7e6) soroban-env interface version 85899345977 stellar-xdr 20.0.0-rc1 (d5ce0c9e7aa83461773a6e81662067f35d39e4c1) xdr curr (9ac02641139e6717924fdad716f6e958d0168491)

Rust soroban-sdk = { version = "20.0.0-rc2", default-features = false }

What did you do?

I'm using the generated typescript binding and for a function returning an Option<(u32, u32)> throws an error when, it seems, the value is converted to native.

 error   Type [object Object] was not vec, but [object Object] is
  File:
    .../millionlumenhomepage/mlh-frontend/node_modules/Million/node_modules/soroban-client/lib/contract_spec.js:374:19
  Code:
    373 |             }
> 374 |             throw new TypeError("Type ".concat(typeDef, " was not vec, but ").concat(scv, " is"));
          |                   ^
      375 |           }
      376 |         case _stellarBase.xdr.ScValType.scvAddress().value:
      377 |           return _stellarBase.Address.fromScVal(scv);

The soroban function is like this:

    pub fn coords(env: Env, token_id: u32) -> Option<(u32, u32)> {
        Coords::Xy(token_id).get(&env)?
    }

And the javascript call that throws the error:

    let xy = await million.coords({token_id: parseInt(id)})

Calling the contract with the cli gives:

soroban contract invoke --id $(cat contract.id) --source user1 --network standalone -- coords --token_id 0
[17,31]

vinamogit avatar Dec 01 '23 00:12 vinamogit