Skip to content

4. API Usage

Axorax edited this page Apr 14, 2023 · 1 revision

• Initialize API

To interact with the Duino Coin API with duco.js you still need to create a variable with the below code:

const api = new Duco({
    username: 'axorax'
});

Note: We used 'api' for the variable name here instead of 'miner' to make it easier for the reader to understand but using the variable name 'miner' will also work.

• Catch error in getting data

api.get('shop')
.then(data => {
    console.log(data)
}).catch((error) => {
    console.log(error)
})

The above code shows how to catch errors in getting data. Don't focus on the api.get('shop') part it is described below. You can do this to catch in all the interactions with the API.

The error catching part won't be showed in the other code examples to keep the code shorter and easier to understand.

• Get data about a user

api.get()
.then(data => {
    console.log(data)
})

• Get data about a user (Method - 2)

api.get('user')
.then(data => {
    console.log(data)
})

This will give less information than using api.get()

• Get all Duino Coin statistics

api.get('stats')
.then(data => {
    console.log(data)
})

• Get all non-hidden pools

api.get('pools')
.then(data => {
    console.log(data)
})

• Get balance of a user

api.get('balance')
.then(data => {
    console.log(data)
})

• Get all miners of a user

api.get('miners')
.then(data => {
    console.log(data)
})

• Get all transactions of a user

api.get('transactions')
.then(data => {
    console.log(data)
})

• Get latest transactions of a user

api.get('latestTransactions')
.then(data => {
    console.log(data)
})

• Get data from transaction hash

api.get('hash', '1437cfdcd0dadf286d10a0cf03a61d2e77c089e8')
.then(data => {
    console.log(data)
})

• Get data from transaction id

api.get('id', 1251235)
.then(data => {
    console.log(data)
})

• Check user's password

api.auth({
    password: 'testing'
})
.then(data => {
    console.log(data)
})

• Get all items available in the shop

api.get('shop')
.then(data => {
    console.log(data)
})

• Buy an item from the shop

api.buy({
    item: <numeric-value-of-item>,
    password: 'your-password'
})
.then(data => {
    console.log(data)
})

• Send duco to someone

api.send({
    password: 'your-password',
    recipient: 'revox',
    amount: 1,
    memo: 'duco.js'
})

• Exchange duco for another crypto currency

api.exchange({
    password: 'your-password',
    email: 'your-email',
    type: 'ex-type',
    amount: 15000,
    coin: 'crypto-currency-you-want',
    address: 'your-crypto-wallet-address'
})