Developer's Hub
v1.0
API Reference
Title
Message
Create new category
What is the title of your new category?
Edit page index title
What is the title of the page index?
Edit category
What is the new title of your category?
Edit link
What is the new title and URL of your link?
Using of CREDITS API in JS (demo)
Copy Markdown
Open in ChatGPT
Open in Claude
Requirements
Any OS (Windows 10 is used for the example)
Download CREDITS API files: https://github.com/CREDITSCOM/thrift-interface-definitions
Create a folder to which you are going to copy the JS files, create an empty html file, for example, index.html.
Create application
Put changes to index.html
Add CREDITS API Script Files
Javascript
x
<script src="thrift.js"></script><script src="API.js"></script><script src="Signature.js"></script><script src="api_types.js"></script>Add connection to Thrift and request balance
Javascript
<title>CREDITS API JS Demo</title><script>function run(){var url = "http://localhost:8081";var transport = new Thrift.Transport(url);console.log("debug step 1");var protocol = new Thrift.Protocol(transport);console.log("debug step 2");var client = new APIClient(protocol);console.log("debug step 3");var PublicKeyFrom = "H5ptdUUfjJBGiK2X3gN2EzNYxituCUUnXv2tiMdQKP3b";var BytePublicKeyFrom = Base58.decode(PublicKeyFrom);console.log("debug step 4");var obj = client.BalanceGet(BytePublicKeyFrom, 1);console.log("debug step 5");console.log(obj);console.log("debug step 6");document.getElementById('pc-id').innerText = PublicKeyFrom;document.getElementById('bl-id').innerText = 'Integral: ' + obj.amount.integral + ', Fraction: ' + obj.amount.fraction;}function ready() {run();}document.addEventListener("DOMContentLoaded", ready);</script>Check the performance. Call the GetBalance Method.
As the result of the program we see the requested balance: page view:

View via developer tool:

GitHub link: https://github.com/pvl1175/CreditsJSDemo
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
Last updated on
Next to read:
Using of CREDITS API in Python 3 (demo)Discard Changes
Do you want to discard your current changes and overwrite with the template?
Archive Synced Block
Message
Create new Template
What is this template's title?
Delete Template
Message