Item Trading - Discussion

Welcome to the discussion thread about this lecture section. Here you can feel free to discuss the topic at hand and ask questions.

When the game wants to do something with transactions and trading i get this error:

It is a pretty annoying bug and i dont know why it is happening.
@filip

1 Like

Hey @KYNUX/

Could you please share your code so we can review it to help you?

Carlos Z.

Sadly i will only be able to give the code this weekend; and can you tell me which C# file and if you need the playercontroller.cs the fact i changed the movement is not something like a typo because i adapted it for mobile.

Thanks for the support!

Hi i have the same problem like @KYNUX @thecil
When i press the button "Purchase "like in the videos this happends
Screenshot 2021-09-02 115158

The code of the purchase script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EnjinSDK;

public class StoreController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    async public void PurchaseUniCoin()
    {
        string coinTokenId = "30000000000010b6";
        string enjinId = "0";

        string adminAddress = LoginManager.loginManagerInstance.adminAddress;

        EnjinItemParameter [] sendItems= new EnjinItemParameter[]{ EnjinItemParameter.ConstructFungible(enjinId, 1)};
        EnjinItemParameter [] receiveItems= new EnjinItemParameter[]{EnjinItemParameter.ConstructFungible(coinTokenId, 10)};

        IRequestHandler tradeHandler = LoginManager.loginManagerInstance.userIdentity.
            CreateTradeItemRequestHandler(sendItems,receiveItems,adminAddress);

        await tradeHandler.RegisterCallback(RequestEventType.CreateTradePending, requestEvent =>
        {
            Debug.Log("Create Trade Request |Pending Done|");
        });
        
        await tradeHandler.RegisterCallback(RequestEventType.CreateTradeBroadcast, requestEvent =>
        {
            Debug.Log("Create Trade Request |Broadcast Done|");
        });
        
        await tradeHandler.RegisterCallback(RequestEventType.CreateTradeExecuted, async requestEvent =>
        {
            string tradeID = requestEvent.Data.param1;
            Debug.Log("Create Trade Request |Execution Done|");
            
            //accept the trade
            IRequestHandler tradeAcceptHandler = LoginManager.loginManagerInstance.adminIdentity.CompleteTradeItemRequestHandler(tradeID);

            await tradeAcceptHandler.RegisterCallback(RequestEventType.CompleteTradePending, completeEvent =>
            {
                Debug.Log("Complete Trade Request |Pending Done|");
            });
            
            await tradeAcceptHandler.RegisterCallback(RequestEventType.CompleteTradeBroadcast, completeEvent =>
            {
                Debug.Log("Complete Trade Request |Broadcast Done|");
            });
            
            await tradeAcceptHandler.RegisterCallback(RequestEventType.CompleteTradeExecuted, completeEvent =>
            {
                Debug.Log("Complete Trade Request |Execution Done| ~ Trade is done");
            });
            await tradeAcceptHandler.Execute();
        });
        await tradeHandler.Execute();
    }
}
2 Likes

http request 400 means a bad request, might be that the enjin server is not responding, i will check my self and get back to you this weekend, will try to run my code again and should work.

I dont see any error in the code that you provide, so it must be something else :face_with_monocle:

Carlos Z

Ok thx, i hope you can find the problem so i can continue with the course :sweat_smile:

Hey @thecil,
did you already take a look at the problem?
I don’t wanna stress you but i wanna continue with my project and this bug does not let me :face_with_head_bandage:

Hey, sorry for the delay man, I might need to check your project to get a better picture, the issue you refer is could be a syntax issue on your http request to enjin servers, which could be incorrect somewhere.

Would be great if you can upload your project to a github repo so i can replicate the issue myself.

Carlos Z

Yes, sorry for the delay man, I have closely follow filip videos and verify your code, the only issue that i found, which is also named on your terminal is on the last argument function in your tradeHandler callbacks.

Yours:

        await tradeHandler.RegisterCallback(RequestEventType.CreateTradePending, requestEvent =>
        {
            Debug.Log("Create Trade Request |Pending Done|");
        });

Filip:

        await tradeHandler.RegisterCallback(RequestEventType.CreateTradePending, 
        (requestEvent) => {
            Debug.Log("Create Trade Request |Pending Done|");
        });

Carlos Z

1 Like