# ResponseError: code: 3, message: json: cannot unmarshal object into Go value of type string

**URL:** <https://forum.heroiclabs.com/t/responseerror-code-3-message-json-cannot-unmarshal-object-into-go-value-of-type-string/6122>\
**Category:** Runtime Framework\
**Tags:** getting-started, server-framework, typescript\
**Created:** [March 26, 2025, 11:29pm UTC](https://forum.heroiclabs.com/t/responseerror-code-3-message-json-cannot-unmarshal-object-into-go-value-of-type-string/6122 "2025-03-26T23:29:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sakhile\_Mamba](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@Sakhile\_Mamba](https://forum.heroiclabs.com/u/Sakhile_Mamba)\
**Post date:** [March 26, 2025, 11:29pm UTC](https://forum.heroiclabs.com/t/responseerror-code-3-message-json-cannot-unmarshal-object-into-go-value-of-type-string/6122/1 "2025-03-26T23:29:40Z")

</div>

I am trying to update the virtual wallet, but I keep getting this error:  
ResponseError: code: 3, message: json: cannot unmarshal object into Go value of type string

Here is the code on my Flutter frontend:

```auto
// Deposit funds
  Future<bool> deposit(double amount, {String? phoneNumber}) async {
    try {
      // Validate amount
      if (amount <= 0) {
        return false;
      }

      // Prepare payload
      final payload = {
        'amount': amount.toString(),
      };

      // Add phone number if provided
      if (phoneNumber != null) {
        payload['phoneNumber'] = phoneNumber;
      }

      final result = await client.rpc(
        session: session,
        id: rpcProcessDeposit,
        payload: jsonEncode(payload),
      );

      final response = jsonDecode(result!);
      if (response['success'] == true) {
        // Update local balance
        balance.value = (response['balance'] as num).toDouble();
        return true;
      } else {
        print('Deposit failed: ${response['error']}');
        return false;
      }
    } catch (e) {
      print('Error processing deposit: $e');
      return false;
    }
  }

```

Below is my RPC on the server:

```auto
let rpcProcessDeposit: nkruntime.RpcFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, payload: string): string {
    if (!ctx.userId) {
        return JSON.stringify({ success: false, error: "No user ID in context" });
    }

    try {
        const request = JSON.parse(payload);
        const amount = Number(request.amount);
        const phoneNumber = request.phoneNumber || '';

        // Validate amount
        if (isNaN(amount) || amount <= 0) {
            return JSON.stringify({ success: false, error: "Invalid deposit amount" });
        }

        // Minimum deposit check
        const minDeposit = 10;
        if (amount < minDeposit) {
            return JSON.stringify({
                success: false,
                error: `Minimum deposit amount is ${minDeposit} SZL`
            });
        }

        // Validate phone number if provided
        if (phoneNumber && !isValidPhoneNumber(phoneNumber)) {
            return JSON.stringify({
                success: false,
                error: "Invalid phone number. Must be 8 digits starting with 76, 78, or 79"
            });
        }

        // Create a wallet update
        const changeset = {
            "szl": amount // Using the default virtual currency
        };

        // Include transaction metadata
        const metadata = {
            "type": "deposit",
            "phoneNumber": phoneNumber || "N/A"
        };

        // Update wallet
        nk.walletUpdate(ctx.userId, changeset, metadata, true);

        // Get updated balance
        const account = nk.accountGetId(ctx.userId);
        const updatedBalance = account.wallet["szl"] ? account.wallet["szl"] : 0;

        // Log the transaction for records
        logger.info("User %s deposited %d SZL via phone %s", ctx.userId, amount, phoneNumber || "N/A");

        return JSON.stringify({ success: true, balance: updatedBalance });
    } catch (error) {
        logger.error("Error processing deposit: %v", error);
        return JSON.stringify({ success: false, error: String(error) });
    }
}

```

The RPC works perfectly when I use the API explorer in the server’s admin console. What is causing the mentioned error. Please help.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [March 27, 2025, 12:40pm UTC](https://forum.heroiclabs.com/t/responseerror-code-3-message-json-cannot-unmarshal-object-into-go-value-of-type-string/6122/2 "2025-03-27T12:40:19Z")

</div>

Hello @Sakhile_Mamba,

Due to a bug in the Flutter SDK, you’ll need to double encode the payload, changing:

```auto
payload: jsonEncode(payload),

```

to

```auto
payload: jsonEncode(jsonEncode(payload)),

```

should work.

Best.
