dether.js

Gateway between Front App and the detherContracts.

dether.js

API documentation

Examples

DetherJS

DetherJS is Javascript SDK to easily interact with DetherContracts

It provides wrappers for all the public methods of the contract and formats values in and out.

Table of Contents

Install

Use NPM to get the package

npm install --save detherjs
or
yarn add detherjs

Usage

In detherJS you can instanciate 2 object:

  1. dether object: For reading easily all the data present in the contract
  2. dether user object: for changing state of the dether contracts

Instanciate_dether

import DetherJS from "dether.js";

const detherjs = new DetherJS({
  network: "mainnet" // can be kovan or ropsten
});

Inputs

Return value

New instance of DetherJS


Get_Teller

const addr = '0xab5801a7d398351b8be11c439e05c5b3259aec9b';

try {
  const teller = await detherjs.getTeller(addr)
} catch () {
  console.log(e);
}

Inputs

Return value

{
  lat: 1, // Latitude
  lng: 2, // Longitude
  countryId: 'FR', // Country ID
  postalCode: 75019,
  escrowBalance: 0.01, // Escrow balance
  rates: 20, // Fees
  volumeTrade: 0, // Volume of Trade
  nbTrade: 0, // Number of trade
  currencyId: 1, // Currency id (1 === 'USD')
  avatarId: 1, // Avatar ID
  messengerAddr1: 'bobychou', // Telegram username
  ethAddress: '0x085b30734fD4f48369D53225b410d7D04b2d9011', // Ethereum address
}

Get_all_tellers

try {
  const allTellers = await detherjs.getAllTellers();
  console.log(allTellers);
} catch (e) {
  console.log(e);
}

Inputs

getAllTellers can receive an array of addresses

Return value

Array of tellers


Get_Tellers_In_Zone

You can specify a zone to get all the tellers presents in this zone

const opts = {
    countryId: 'CZ', // CZ for Czech republic
    postalCode: '170 00'
};

try {
  const tellersInZone = await detherjs.getZoneTeller(opts);
} catch (e) {
  console.log(e);
}

Inputs

getZoneTeller can receive an array of zones ID

Return value

Array of tellers


Get_Teller_Balance

const addr = "ETH_ADDRESS";

try {
  const balance = await detherjs.getTellerBalance(addr);
} catch (e) {
  console.log(e);
}

Inputs

Return value

Receive escrow balance of teller


Instanciate_User

You need to create a user:

const privateKey = 'PRIV_KEY';
const userPassword = '1234';

const wallet = new DetherJS.Ethers.Wallet(privateKey);
const encryptedWallet = await wallet.encrypt(userPassword);

const User = await dether.getUser(encryptedWallet);

Add_Sell_Point

User need to be certify first

const password = "123456789";

const opts = {
  lat: 1.12,
  lng: 2.21,
  countryId: "CZ",
  postalCode: "170 00",
  rates: 20.2,
  avatar: 1,
  currencyId: 2,
  messenger: "telegram",
  amount: 0.1
};

try {
  const hash = await User.addTeller(opts, password);
} catch (e) {
  console.log(e);
}

Inputs

Return value

Return receipt of transaction


Add_Eth

As a seller, add Eth in your sell point

const password = "123456789";

const opts = {
  amount: 1, // 1 ETHER
  gasPrice: 20000000000 // 20 GWEI
};

try {
  const hash = await User.addEth(opts, password);
} catch (e) {
  console.log(e);
}

Inputs

Return value

Return receipt of transaction


Send_To_Buyer

const password = 'Pass';

const opts = {
  amount: 0.1,
  receiver: 'ETH_ADDRESS',
};

try {
  const sendCoinTransaction = await User.sendToBuyer(opts, password);
} catch (e) {
  console.log(e);
}

Inputs

Return value

Return receipt of transaction


Delete_Sell_Point

const password = "123456789";

try {
  const hash = await User.deleteSellPoint(password);
} catch (e) {
  console.log(e);
}

Inputs

Return value

Return receipt of transaction


certify_new_user

the address who certify need to be delegate. For this version only dether is delegate.

const password = "123456789";

const opts = {
  user: "0x0", // eth address
  nonce: 1, //
  gasPrice: 20000000000 // 20 GWEI
};

try {
  const hash = await User.certifyNewUser(opts, password);
} catch (e) {
  console.log(e);
}

inputs

Return value

Return receipt of transaction


certify_new_user_API_CALL

For Dapp willing to certify user using the dether sms verification, you need to do an API call

TO DO


## TO DO

Add certify new user API