Improvement Suggestions - Discussion

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

For those wondering where to find some documentation on the Enjin SDK. It’s within the Enjin SDK package dowloaded in Unity at the beginning of this course, in Assets/Enjin/SDK/Docs/SDKDocs.zip
Unzip the file, open docs.html in your browser. You will find, under Details, each GraphQL query with links to their equivalent functions in Unity, at the bottom.

2 Likes

Hi @filip & team. I managed to download the newer SDK from the Unity Asset Store and some of the functions now are a lot cleaner to understand and use. E.g.

async public void PurchaseSword()
    {
      string coinTokenId="3800000000000f74";
      string swordTokenId="3800000000000f7a";
      string adminAddress=AccountManager.instance.adminIdentity.wallet.ethAddress;

      TokenValueInputData[] playerTokens = new TokenValueInputData[] { new TokenValueInputData(coinTokenId,  null, 1 ) };
      TokenValueInputData[] swordTokens  = new TokenValueInputData[] { new TokenValueInputData(swordTokenId, null, 1 ) };

      Request tradeRequest;

      Enjin.SDK.Core.Enjin.IsDebugLogActive=true;

      tradeRequest = CreateTradeRequest(
        AccountManager.instance.userIdentity.id,
        playerTokens,
        adminAddress,
        swordTokens,
        delegate(RequestEvent x) {
          string tradeId = x.data.param1;
          Debug.Log("CREATE TRADE Callback! "+x.model+" "+x.event_type+
                    " "+x.contract+" "+tradeId);

          tradeIdToComplete = tradeId; // Things break if we do another Create in this callback :-(
        }
      );

      Debug.Log("Create trade request state: "+tradeRequest.state);

    }

There is a gotcha in that trying to send a COMPLETE_TRADE request from within a CREATE_TRADE callback seems to cause a websockets error, but it is easily solved by saving the tradeId, and sending the COMPLETE_TRADE request from Update() the next time it is called.

// Update is called once per frame
    void Update()
    {
        if (tradeIdToComplete != null) {

          Request completeTradeRequest = CompleteTradeRequest(
                AccountManager.instance.adminIdentity.id,
                tradeIdToComplete,
                delegate(RequestEvent x) {
                  Debug.Log("COMPLETE TRADE Callback! "+x.model+" "+x.event_type+" "+x.contract+" "+x.data.param1);
                }
            );

            Debug.Log("Complete trade request state: "+completeTradeRequest.state);
            tradeIdToComplete = null;
        }
    }

Cheers

5 Likes

Hey Billy I could really use some advice, I’ve spoken with an admin in Enjin Discord who attempted to help me locate docs on SDK but failed because after speaking with the Enjin team they stated the SDK is depreciated and they are currently working on an SDK that wouldn’t require unity. How were you able to navigate the new SDK I would really like to finish this project and build it out further from there. Any help would be greatly appreciated.

@ibn5x

Hi Mikal, you just have to read the code. Start at SDK/Core/Enjin.cs and focus on the ‘public’ methods. Expand out to the other classes in that folder. If you have specific questions, happy to help. I can share other code snippets too, but you’ll benefit more if you figure it out on your own.

Also, and this might help, check out the thread Creating Test User Account - Discussion (for context) and in particular my reply here Creating Test User Account - Discussion

Hope that helps. Best of luck.

Cheers

3 Likes

Hey, Billy thank you for your time. I appreciate you point me in the right direction, Now I’m off to the races!

1 Like