stellar / js-soroban-client

Main Soroban client library for the Javascript language
https://stellar.github.io/js-soroban-client/
Apache License 2.0
22 stars 17 forks source link

XDR Write Error: [object Object] is not a ScVal #124

Closed rust-master closed 1 year ago

rust-master commented 1 year ago

I'm using the Typescript client and facing an issue on React side when invoking the write function of the contract.

Error:

caught (in promise) TypeError: XDR Write Error: [object Object] is not a ScVal
    at Function.value (soroban-client.min.js:2:1)
    at r.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at r.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at Function.value (soroban-client.min.js:2:1)
    at r.value (soroban-client.min.js:2:1)

Code Snippet:

import * as SorobanClient from "soroban-client";
import * as exampleProject from "ExampleProject"; // Typescript client

await exampleProject.invoke({
        method: "set_name",
        args: [
          SorobanClient.xdr.ScVal.scvString("Rust")
        ],
        fee: 100000,
      });

Contract Function:

 pub fn set_name(env: Env, value: String) {
        env.storage().instance().set(&NAME, &value);
    }
AkhtarAmir commented 1 year ago

The same error "[object Object] is not a ScVal" affecting us too even though the values are being converted perfectly to ScVal.

AkhtarAmir commented 1 year ago

Hey @rust-master, even after update I am still facing the same error can you provide a snippet how to pass the values now for avoiding this or is there anything else that needs to be changed?