CREXT API

Welcome CREXT API docs! Here you can find the documentation on how to use the API that is injected into every page someone visits.

Get started

CREXT injects a simple javascript file into every page someone visits. The only requirement for this is that the website should support HyperText Transfer Protocol Secure (https)

Add logo to connection request

To add your logo to a connection request, simply add the logo you want to be displayed as logo.png in the root folder of your website.

Detect CREXT

When CREXT is not installed it will return false otherwise it will result true

function checkExtension() {
  if(typeof(CREXT) === 'undefined') {
    return false;
  } else {
    return true;
  }
}

Request current selected network

Users can switch easily between CreditsNetwork (MainNet) and TestNet. With the CREXT.network() you can request the current selected network.

Result value Description
1 CreditsNetwork (MainNet)
0 TestNet

Example request

CREXT.network()
.then(r => console.log(r));

Example response

{
  "success": true,
  "result": 1
}

Request current public key

CREXT.getKey()

Property Description
id (optional) id for own use, will be returned in response

Example request

CREXT.getKey({"id":"test"})
.then(function(val) { // success true
  console.log(val);
})
.catch(function(val) { // success false
  console.log(val);
});

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "publicKey": "5V9h5DvH9nPiiVEifnZ8716d2SQ5udTkFnuBRqCkkuvi"
  }
}

Wallet functions

Request balance

Request the balance of a public key on the Credits blockchain with the CREXT.balanceGet() function.

Property Description
key (required) public key
id (optional) id for own use, will be returned in response

Example request

CREXT.balanceGet({
  key: "5V9h5DvH9nPiiVEifnZ8716d2SQ5udTkFnuBRqCkkuvi",
  id: "test"
})
.then(function(val) {
  console.log(val);
})
.catch(function(val) {
  console.log(val);
});

Example request body

{
  "key": "5V9h5DvH9nPiiVEifnZ8716d2SQ5udTkFnuBRqCkkuvi",
  "id": "test"
}

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "balance": "80.03379053707034298",
    "fraction": "03379053707034298",
    "integral": 80
  }
}

Request wallet data

Requesting the data of a wallet is possible with the CREXT.walletDataGet() function.

Property Description
key (required) public key
id (optional) id for own use, will be returned in response
CREXT.walletDataGet({
  key: "5V9h5DvH9nPiiVEifnZ8716d2SQ5udTkFnuBRqCkkuvi",
  id: "test"
})
.then(function(val) {
  console.log(val);
})
.catch(function(val) {
  console.log(val);
});

Example request body

{
  "key": "5V9h5DvH9nPiiVEifnZ8716d2SQ5udTkFnuBRqCkkuvi",
  "id": "test"
}

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "balance": {
        "balance": "80.03379053707034298",
        "fraction": "03379053707034298",
        "integral": 80
    },
    "lastTransactionId": 52,
    "walletId": 407  
    }
}

Transaction

Create transaction

Sending a transaction using CREXT is easy. CREXT handles signing the transaction and sending it to an active node. CREXT.sendTransaction() returns a promise with the result of the transaction.

Property Description
id (optional) id for own use, will be returned in response
target (required) target public key
amount (required) amount to send (in CS)
fee (required) maximum fee willing to pay (in CS)
UserData (optional) to store some userdata inside the transaction

Example request

CREXT.sendTransaction({
  id: "test",
  target: "7tiMoADn9VJfP3xEf58BAUj85mJuGmfqTyN86JeCk9TA",
  amount: "1.0",
  fee: "1.0"
})
.then(function(val) {
  console.log(val);
})
.catch(function(val) {
  console.log(val);
});

Example request body

{
  "id": "test",
  "target": "7tiMoADn9VJfP3xEf58BAUj85mJuGmfqTyN86JeCk9TA",
  "amount": "1.0",
  "fee": "1.0"
}

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "roundNum": 1309526,
    "smart_contract_result": null,
    "status": {
        "code": 0,
        "message": "Success 35000000000042A4D652F43CF6E3A536E068AFB27344F7CE5C1FBC42591B3B5C5DD2CEE849C3666581D016A55029F009CE2D555E6682CAA97A3AEEF49A06EA1CB9FDE9101B55010000000000000000000000664C0100"
    }
  }
}

Example response (popup closed by user)

{
  "success": false,
  "id": "test",
  "message": "Window closed by user"
}

Example response (transaction rejected)

{
  "success": false,
  "id": "test",
  "message": "Transaction rejected by user"
}

Smart Contracts

Deploying smart contracts and executing smart contract functions work via the same CREXT function as sending a regular transaction; CREXT.sendTransaction().

Deploy smart contract

Property Description
id (optional) id for own use, will be returned in response
fee (required) maximum fee willing to pay (in CS)
smart Please see smart below
smart Description
code (required) smart contract code

Example contract

let contractCode = `import com.credits.scapi.annotations.*;
import com.credits.scapi.v0.*;

public class MySmartContract extends SmartContract {

 public MySmartContract() {
 }
}`;

Example request

CREXT.sendTransaction({
  id: "test",
  fee: "1.0",
  smart: {
    code: contractCode
  }
})
.then(function(val) {
  console.log(val);
})
.catch(function(val) {
  console.log(val);
});

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "contractAddress": "GXfZtSVru4nSskG6Hc9Ro1DXcWoCs8naTm3LCobqM1Em",
    "roundNum": 1310161,
    "smart_contract_result": null,
    "status": {
      "code": 0,
      "message": "Success 36000000000042A4D652F43CF6E3A536E068AFB27344F7CE5C1FBC42591B3B5C5DD2CEE849C3E6BA56061D7845AD57E507D8427832334B939FF060A6ED3FC1B5C6CEF1066A7E0000000000000000000000009A4C0101DB0100000B0001000000000F00020C000000000F00030B00000000020004000C00050B00010000009E696D706F727420636F6D2E637265646974732E73636170692E616E6E6F746174696F6E732E2A3B0A696D706F727420636F6D2E637265646974732E73636170692E76302E2A3B0A0A7075626C696320636C617373204D79536D617274436F6E747261637420657874656E647320536D617274436F6E7472616374207B0A0A207075626C6963204D79536D617274436F6E74726163742829207B0A207D0A7D0F00020C000000010B00010000000F4D79536D617274436F6E74726163740B0002000000E2CAFEBABE00000034000D0A0003000A07000B07000C0100063C696E69743E010003282956010004436F646501000F4C696E654E756D6265725461626C6501000A536F7572636546696C650100144D79536D617274436F6E74726163742E6A6176610C0004000501000F4D79536D617274436F6E7472616374010022636F6D2F637265646974732F73636170692F76302F536D617274436F6E7472616374002100020003000000000001000100040005000100060000002100010001000000052AB70001B10000000100070000000A0002000000060004000700010008000000020009000B000300000000080004000000000000"
    }
  }
}

Execute smart contract

Property Description
id (optional) id for own use, will be returned in response
target (required) target contract address
fee (required) maximum fee willing to pay (in CS)
smart Please see smart below
smart Description
method (required) valid smart contract method
params (optional) (array) parameters should match method input

Example request

CREXT.sendTransaction({
  id: "test",
  target: "6co6xHtQSLC6EhfMmE7E1wX9ETTB6H3PovpPChuNg2om",
  fee: "1.0",
  smart: {
      method: "returnValue",
      params: [true, "random string"]
  }
})
.then(function(val) { // Success: true
  console.log(val);
})
.catch(function(val) { // Success: false
  console.log(val);
});

Example response

{
  "success": true,
  "id": "test",
  "result": {
    "roundNum": 1755426,
    "smart_contract_result": "return value from contract execution",
    "status": {
        "code": 0,
        "message": "Success 6E4E00000000FAFAD820587CBE12083127BB0C056C8EC50C2C5645FB404C601D5E66E8543E9F5375E43116EC8B16103DCCEF54AC19436B4D50DCBB6AE970BC6C9D97D78E1824000000000000000000000000664C0101350000000B00010000000B72657475726E56616C75650F00020C0000000202000301000B00110000000176000F00030B000000000200040000"
    }
  }
}

Example response (incorrect amount of parameters)

{
  "success": false,
  "id": "test",
  "message": "x params given, only x params allowed."
}

Check contract state

To check the state of a contract, without paying any transaction fees, it's recommended to use the CREXT.contractState function. This function allows to check the state, or any variable, of a contract. To return the current value there must be a function that returns this value.

As there is no visible transaction on the Credits Monitor a random keypair is used to request this value.

Property Description
id (optional) id for own use, will be returned in response
target (required) target contract address
method (required) valid smart contract method
params (optional) (array) parameters should match method input

Example request

CREXT.contractState({
    id: "test",
    target: "C2e5NyvG4cLaZYN5uqPmuVNuZLbgcdgapKnmFZiFVJiY",
    method: "balanceOf",
    params: ["7qk4vxgdqQGZJGVPk746X135DGTXTBrk52AAdzmRSkxK"]
}).then(function(r) {
    console.log(r);
});

Example result

{
  "success": true,
  "id": "test",
  "result": "0.00000"
}
Show examples in:
CREXT API Documentation