@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.
2 lines (1 loc) • 1.9 kB
JavaScript
;var l=t=>{throw TypeError(t)};var d=(t,e,s)=>e.has(t)||l("Cannot "+s);var a=(t,e,s)=>(d(t,e,"read from private field"),s?s.call(t):e.get(t)),y=(t,e,s)=>e.has(t)?l("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),r=(t,e,s,o)=>(d(t,e,"write to private field"),o?o.call(t,s):e.set(t,s),s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u={nebula:"11482601649","nebula-testnet":"37084624"},h={"us-east-2":"https://player.us-east-2.eidolon.gg"};var n,i;class j{constructor({region:e,apiKey:s}){y(this,n);y(this,i);r(this,n,s),r(this,i,h[e])}changeRegion(e){r(this,i,h[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:u[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:u[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;exports.PlayerApi=j;exports.urls=h;