@eidolon-labs/player-sdk
Version:
@eidolon-labs/player-sdk is a lightweight API wrapper for the Eidolon Player API; the invisible gaming layer for blockchain.
110 lines (109 loc) • 2.56 kB
JavaScript
var y = (t) => {
throw TypeError(t);
};
var l = (t, e, s) => e.has(t) || y("Cannot " + s);
var a = (t, e, s) => (l(t, e, "read from private field"), s ? s.call(t) : e.get(t)), h = (t, e, s) => e.has(t) ? y("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), r = (t, e, s, o) => (l(t, e, "write to private field"), o ? o.call(t, s) : e.set(t, s), s);
const d = {
nebula: "11482601649",
"nebula-testnet": "37084624"
}, u = {
"us-east-2": "https://player.us-east-2.eidolon.gg"
};
var n, i;
class g {
constructor({
region: e,
apiKey: s
}) {
h(this, n);
h(this, i);
r(this, n, s), r(this, i, u[e]);
}
changeRegion(e) {
r(this, i, u[e]);
}
setApiKey(e) {
r(this, n, e);
}
async createPlayer({
chainName: e,
suppliedId: s
}) {
return await (await fetch(`${a(this, i)}/v1/players`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": a(this, n)
},
body: JSON.stringify({
chainName: e,
suppliedId: s
})
})).json();
}
async sendTransaction({
chainName: e,
data: s,
playerId: o,
value: p,
to: c
}) {
return await (await fetch(`${a(this, i)}/v1/transactions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": a(this, n)
},
body: JSON.stringify({
chainId: d[e],
data: s,
playerId: o,
value: p,
to: c
})
})).json();
}
async estimateGas({
chainName: e,
data: s,
playerId: o,
value: p,
to: c
}) {
return await (await fetch(`${a(this, i)}/v1/transactions/estimate`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": a(this, n)
},
body: JSON.stringify({
chainId: d[e],
data: s,
playerId: o,
value: p,
to: c
})
})).json();
}
async getPlayer({ playerId: e }) {
return await (await fetch(`${a(this, i)}/v1/players/${e}`, {
headers: {
"Content-Type": "application/json",
"x-api-key": a(this, n)
}
})).json();
}
async getPlayerBySuppliedId({ suppliedId: e }) {
return await (await fetch(`${a(this, i)}/v1/players/recover/${e}`, {
headers: {
"Content-Type": "application/json",
"x-api-key": a(this, n)
}
})).json();
}
}
n = new WeakMap(), i = new WeakMap();
export {
g as PlayerApi,
u as urls
};