Include our scripts in your web page
The first step is to include our script into your web pages. You can include the links statically but it is better to load the script lines dynamically from our server.
The Java Script APIs are mainly used by our progressive Web Wallet: https://coin.codeb.io
To request the lines use:
https://coin.codeb.io/blocks.aspx?block=<customerID>
Note: Default customerID is java
Please note that it is good practice to include the java script ONLY if needed. For example only after the user authenticated to your system.
Input Fields
amount: Amount of base currency or coins to transfer on triggertransfer or triggercointransfer
recipient: Holds the recipient address for base currency transfers triggered by triggertransfer
crecipient: Holds the recipient address for a coin transfer triggered by triggercointransfer
comments: Input field for the subject of a coin transfer triggered by triggercointransfer
Output Fields
baddress: Blockchain address of authenticated user
ebalance: Base currency balance of authenticated user
mybalance: Coin balance. Can be updated with function mybalance
rbalance: Output of receiver base currency balance on triggertransfer or filled by function: recipientbalance
obalance: Output of receiver coin balance on triggercointransfer or filled by function: crecipientbalance
totalsupply: Total coin supply – updated by function totalbalance
transactionreceipt: Will contain the transaction receipt of the coin transfer triggered by triggercointransfer
Buttons
Buttons can be used to trigger an action.
tbutton: ID of button calling triggertransfer or triggercointransfer
Actions
totalbalance: updates field totalsupply with the total supply of coins
senderbalance: Update base currency balance of authenticated user. Ideally triggered by button with ID: sbbutton
mybalance: Returns coin balance in text field with ID: mybalance
Generate or load key with generatekeyanddisplay
Every crypto operation has to be signed with the private key of the user. To generate a new or display a private key from the encrypted storage the function generatekeyanddisplay() has to be called.
If the entered password is able to decrypt the key from the secure storage then that key will be returned. In case that operation fails a new key is generated.
You can call the function for example from an onclick event of a button:
<input id=”generatekey” type=”button” value=”Generate Key” onclick=”generatekeyanddisplay()“/>
The password to protect the private key will be read by generatekeyanddisplay() from a text field with ID “keypass“.
The HTML could look like: <input id=”keypass” type=”password” />
The generated key will be outputted to a field with ID “pkey” and the blockchain address will be outputted to field with ID “baddress“.
<input id=”pkey” type=”text”/><input id=”baddress” type=”text”/>
If a field “ebalance” exists the balance will be written to that field.
<input id=”ebalance” type=”text”/>
Import an external or saved key with importkey
It is also possible to import an existing private key with function importkey()
The password to protect the private key will be read by importkey() from a text field with ID “keypass“.
The HTML could look like: <input id=”keypass” type=”password” />
The 12 word private key will be read from field with ID “pkey”
<input id=”pkey” type=”text”/><input id=”baddress” type=”text”/>
On import success the address of the private key will be written to field with ID “baddress”
<input id=”baddress” type=”text”/>
If a field “ebalance” exists the balance will be written to that field.
<input id=”ebalance” type=”text”/>
Unlock encrypted private key in browsers secure storage with checkwallet
With the command checkwallet() you unlock and load the private key from the encrypted secure storage of you browser to be used for transaction signing.
if a text field with ID “keypass” exists the content will be used to unlock the key.
<input id=”keypass” type=”password” />
if a button with ID “tbutton” exists it will be enabled on success
If the text fields with the following IDs exist they will be filled with their values:
baddress = blockchain address
ebalance = balance of base currency
totalsupply = total supply of coins
mybalance = users balance of coins
Transfer of base currency with triggertransfer
If the private key of the secure store of your browser is unlocked you can transfer the base currency of the chain with the command triggertransfer().
If a button with ID “tbutton” exists it will be disabled.
The recipient address is read from a text field with ID “recipient”
<input id=”recipient” type=”text” />
The amount to be transferred in base currency is read from a field with ID “amount”
<input id=”amount” type=”text” />
If a text field with ID “rbalance” exists then the balance of base currency will be written to that field on success
<input id=”rbalance” type=”text” />
If a field “ebalance” exists the balance of the sender after the transfer will be written to that field on success
<input id=”ebalance” type=”text”/>
If a button with ID “tbutton” exists it will be enabled after the transfer.
Transfer of coins with triggercointransfer
If the private key of the secure store of your browser is unlocked you can transfer coins with the command triggercointransfer().
If a button with ID “tbutton” exists it will be disabled.
The recipient address is read from a text field with ID “crecipient”
<input id=”crecipient” type=”text” />
The amount to be transferred in base currency is read from a field with ID “amount”
<input id=”amount” type=”text” />
If a text field with ID “obalance” exists then the coin balance will be written to that field on success
<input id=”obalance” type=”text” />
If a field “mybalance” exists the balance of the sender after the transfer will be written to that field on success
<input id=”mybalance” type=”text”/>
If a button with ID “tbutton” exists it will be enabled after the transfer.