Hivejs: How to transfer Splinterland-Cards Part 2? Wie transferiert man Splinterlandskarten Teil 2? #11

avatar

EN

In my last post I showed how to transfer HSBI and Splinterland cards to other users. I only explained how it works and showed a small example where you had to enter the ID of the card yourself. This can be found easily at peakmonsters.com.

In this post I show how to check if username exists at Splinterlands and how to get your cards and their IDs. This has nothing to do with Hivejs, just the transfer at the end. But maybe someone is interested and then you don't have to search for it like me.

Splinterlands API

There is an API from Splinterlands, its URL is https://api.splinterlands.io/ and you can find the documentation here https://github.com/kiokizz/Splinterlands-API.

Check users

With the URL https://api.splinterlands.io/players/details?name= you can get details about a user, just add the username at the end.

You can test this in the browser, here are two examples, one an existing user and one a non-existing user:
https://api.splinterlands.io/players/details?name=mein-senf-dazu

https://api.splinterlands.io/players/details?name=hive-coding

As you can see, the output for a non-existing user is the error "Player @hive-coding not found." and for an existing user the data about the user. The data output is a JSON.

In the browser we see the directly readable data, but we can also display the raw data.

Retrieve your cards

Using the URL https://api.splinterlands.io/cards/collection/ you can retrieve a player's card collection, just append the player name, e.g. https://api.splinterlands.io/cards/collection/mein-senf-dazu.

You will get all the cards with some details about the cards, including the ID

For the transfer the ID is important and that "market_id" and "delegated_to" are "null". If there is an ID or a player name in it, like in the picture above, this card is currently not released for transfer, because it is for sale, rented or delegated.

The Script

Here a short explanation to my example script:

At the end of the script in line 132 the function loadCardDetail() is called.

This will retrieve the data for each card, including which edition the cards belong to, the name of the card, type.
To be able to display an image, we need the edition and the name, among other things. Once the data is loaded, it is stored in cardDetails and the LoadCards function is called (lines 47 and 48).

The function loadCards loads all my cards (from my main account @mein-senf-dazu) and displays them in a table.
It asks in line 67 that the card is neither rented, delegated nor for sale and that the card has only 1 XP.

Here, of course, you can still use one or the other to filter. I chose 1 XP to avoid accidentally sending good cards.

In line 75-80 a new line and thus card is added to the table. Thereby a checkbox, which has the value of the card UID, the image, the name and the card UID is output.

The URL for the image I have to assemble a bit in the process, unfortunately this is not stored in the details and I had to test a bit to figure out the exact structure.

In line 93-102 the button is assigned what should happen after clicking. The selected cards are read in and passed to the sendCardtouser function together with the entered username.

The function sendCardtouser first checks if the user is a player at Splinterlands and only if this is the case, the cards will be transferred. How the structure of the call must be, I have described in my last post.

Is also actually quite simple or? As long as you know it once and know what to look out for.

The whole thing is of course nicer implemented on https://peakmonsters.com/ and can be used there very easily. But maybe you have special wishes that are not possible there and can implement it now.

Do you use the site and do you miss a function, then let me know. I had seen here and there that someone had written an extension for Peakmonsters.

You can find the example here, use this only locally, never enter your private active key on jsfiddle!

If you have any questions, feel free to leave a comment. It's best to mention @mein-senf-dazu, so I'll get it.

Translated with www.DeepL.com/Translator (free version)

DE

In meinem letzten Beitrag habe ich gezeigt, wie man HSBI und Splinterlandskarten an andere Nutzer transferiert. Dabei habe ich nur die Funktionsweise erklärt und ein kleines Beispiel gezeigt erstellt, bei dem man selber die ID der Karte eingeben musste. Diese kann man ganz einfach bei peakmonsters.com finden.

In diesem Beitrag zeige ich, wie man prüft, ob der Username vergeben ist bei Splinterlands und wie man an seine Karten und deren IDs kommt. Dies hat nichts mit Hivejs zu tun, nur der Transfer am Ende. Aber vielleicht interessiert es doch jemanden und dann muss man nicht wie ich danach suchen.

Splinterlands API

Es gibt eine API von Splinterlands, deren URL ist https://api.splinterlands.io/ und die Dokumentation findet ihr hier https://github.com/kiokizz/Splinterlands-API.

Nutzer prüfen

Über die URL https://api.splinterlands.io/players/details?name= kann man Details zu einem User abrufen, dafür einfach den Nutzernamen am Ende anfügen.

Ihr könnt das einmal im Browser testen, hier zwei Beispiele, ein existierender Nutzer und einmal ein nicht existierender Nutzer:
https://api.splinterlands.io/players/details?name=mein-senf-dazu

https://api.splinterlands.io/players/details?name=hive-coding

Wie ihr sehen könnt, wird bei einem nicht existierenden Nutzer der Fehler "Player @hive-coding not found." ausgegeben und bei einem existierenden Nutzer die Daten zu dem Nutzer. Die Daten werden als JSON ausgegeben.

Im Browser sehen wir die direkt leserlich, können uns aber auch die Rohdaten anzeigen lassen.

Deine Karten abrufen

Über die URL https://api.splinterlands.io/cards/collection/ kann man die Karten eines Spielers abrufen, dazu muss man nur dessen Spielername anhängen, z.B. https://api.splinterlands.io/cards/collection/mein-senf-dazu.

Ihr erhaltet alle Karten mit einigen Details zu den Karten, u.a. die ID

Für den Transfer ist die ID wichtig und dass "market_id" sowie "delegated_to" "null" sind. Sofern, wie beim oberen Bild, eine ID drin steht oder ein Spielername, ist diese Karte aktuell nicht für den Transfer freigegeben, da diese zum Verkauf steht, vermietet oder delegiert ist.

Das Script

Hier eine kurze Erklärung zu meinen Beispielscript:

Am Ende des Scriptes in Zeile 132 wird die Funktion loadCardDetail() aufgerufen.

Dadurch werden die Daten zu den einzelnen Karten abgerufen, u.a. zu welcher Edition die Karten gehören, der Name der Karte, Art.
Um ein Bild anzeigen zu können, benötigen wir u.a. die Edition und den Namen. Sobald die Daten geladen sind, werden diese in cardDetails gespeichert und die Funktion LoadCards aufgerufen (Zeile 47 und 48).

Die Funktion loadCards lädt alle meine Karten (von meinem Hauptaccount @mein-senf-dazu) und zeigt diese in einer Tabelle an.
Dabei wird in Zeile 67 abgefragt, dass die Karte weder vermietet, delegiert noch zum Verkauf steht und dass die Karte nur 1 XP hat.

Hier kann man natürlich noch das eine oder andere nutzen zum Filtern. Ich habe 1 XP gewählt, um nicht versehentlich gute Karten zu verschicken.

In Zeile 75-80 wird eine neue Zeile und somit Karte der Tabelle hinzugefügt. Dabei wird eine Checkbox, die den Wert der Karte-UID hat, das Bild, der Name und die Karten-UID ausgegeben.

Die URL für das Bild muss ich dabei etwas zusammenbauen, leider ist diese nicht in den Details gespeichert und ich musste etwas testen, um den genauen Aufbau herauszufinden.

In Zeile 93-102 wird dem Button zugewiesen, was passieren soll nach dem Klicken. Die ausgewählten Karten werden eingelesen und zusammen mit dem eingegebenen Nutzernamen an die Funktion sendCardtouser übergeben.

Die Funktion sendCardtouser prüft erst einmal, ob der Nutzer ein Spieler bei Splinterlands ist und nur sofern das der Fall ist, werden die Karten transferiert. Wie der Aufbau des Aufrufs sein muss, habe ich in meinem letzten Beitrag beschrieben.

Ist doch auch eigentlich ganz einfach oder? Sofern man es einmal weiß und weiß, worauf man achten muss.

Das Ganze ist auf https://peakmonsters.com/ natürlich schöner umgesetzt und kann da sehr einfach genutzt werden. Aber vielleicht habt ihr ja doch speziell Wünsche, die dort nicht möglich sind und könnt es nun damit umsetzen.

Nutzt ihr die Seite und vermisst ihr da eine Funktion, dann lasst es mich doch wissen. Ich hatte hier und da schon mal gesehen, dass jemand für Peakmonsters eine Erweiterung geschrieben hatte.

Das Beispiel findet ihr hier, nutzt diesen nur Lokal, gebt nie euren privaten Aktiv-Schlüssel auf jsfiddle ein!

Wer Fragen hat, kann gern ein Kommentar da lassen. Am besten @mein-senf-dazu erwähnen, damit ich es mitbekomme.



0
0
0.000
10 comments
avatar

Is there a way to get the full transaction list with prices paid etc?

0
0
0.000
avatar
avatar

yes, but the history is limited.

0
0
0.000
avatar

I think you have to use
https://github.com/kiokizz/Splinterlands-API#transaction-history
and loop through all transactions and look for what you need.

Maybe @kiokizz can help, also why https://api.splinterlands.io/market/for_sale is not working.

0
0
0.000
avatar

Hello. I haven't been actively updating the API documentation here for some time. I would like to revisit it soon, though I've been occupied with other things.

The transaction history is only reliable for bulk transactions back approx 31 days. You can individually query a market transaction using the hive blockchain transaction id, though these do have some limitations on early transactions - don't have a list exactly, but it is fairly reliable.

https://api2.splinterlands.com/transactions/lookup?trx_id=6933e74e7a415b1c8eaaef15cf2c74586272c0b9

And https://api.splinterlands.io/market/status?id=trxidxxx-23 (index of card in transaction) to find if a card actually sold.

To get list of prices for cards grouped: https://api.splinterlands.io/market/for_sale_grouped

To get list of prices for individual card listings
https://api2.splinterlands.com/market/for_sale_by_card?card_detail_id=331&gold=false&edition=3

No perfect answers with the history API seeming to be a relatively low priority as the game has been developed.

@hive-coding @mypathtofire

0
0
0.000
avatar

Thank you for your answer.

Have one more Question.
Do you know how i can get the bcx for a Card?

I want to show Cradcollection sorted by market price. I can get low_price_bcx with https://api.splinterlands.io/market/for_sale_grouped

For most cards the bcx seams to be same as xp.

But for some Cards i have compered it is not equal.

I looked at peakmonster, for bcx and xp in the api.

Here is an example where it do not match:

https://ecency.com/hive-121566/@mein-senf-dazu/splinterlands-xp-vs-bcx

0
0
0.000
avatar

Hello. I can probably write up a more detailed answer, but the short of it is this:

The old XP system was used for card ids as follows, before it was replaced with the much simpler 1 xp = 1 bcx. Back before the game play was designed there were plans for cards to level in game-play. This didn't eventuate, leading to the simplification we currently see.

There are a few exceptions in how the XP are split, but I'd need more time to split that up in a post to explain it all.

``
if (id <= 134 || (id >= 205 && id <= 208) || (id >= 212 && id <= 223 || id === 238 || id === 237))

let alpha_beta_xp = {
alpha: {
false: {0: 20, 1: 100, 2: 250, 3: 1000},
true: {0: 250, 1: 500, 2: 1000, 3: 2500}
},
beta: {
false: {0: 15, 1: 75, 2: 175, 3: 750},
true: {0: 200, 1: 400, 2: 800, 3: 2000}
},
}
``

All other cards are the new XP system, unless I've missed something.

0
0
0.000
avatar

Congratulations @hive-coding! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 100 upvotes.
Your next target is to reach 200 upvotes.
You received more than 1000 upvotes.
Your next target is to reach 1250 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

HiveBuzz World Cup Contest - Recap of Day 9
Hive Power Up Day - December 1st 2022
HiveBuzz World Cup Contest - Check your ranking
Support the HiveBuzz project. Vote for our proposal!
0
0
0.000