• R/O
  • HTTP
  • SSH
  • HTTPS

Bytom-Dapp-Demo: Repository summary

A simple deposit and profit bytom dapp demo


Recent Commits RSS

Rev. Time Author Message
96b49cf 2022-02-11 02:18:23 dependabot[bot] dependabot/npm_and_yarn/node-sass-7.0.0 Bump node-sass from 4.11.0 to 7.0.0 Bumps [node-sass](h...
234fea7 2021-01-05 16:41:34 dependabot[bot] dependabot/npm_and_yarn/axios-0.21.1 Bump axios from 0.18.0 to 0.21.1 Bumps [axios](https://...
ddf4020 2020-09-04 19:07:13 dependabot[bot] dependabot/npm_and_yarn/node-sass-4.13.1 Bump node-sass from 4.11.0 to 4.13.1 Bumps [node-sass](...
587eb93 2020-04-30 11:23:48 dependabot[bot] dependabot/npm_and_yarn/jquery-3.5.0 Bump jquery from 3.3.1 to 3.5.0 Bumps [jquery](https://...
ed6b30d 2019-07-22 15:34:48 Zhiting Lin master update the account referesh balance.
ba5dd81 2019-07-22 15:17:03 Zhiting Lin update the contract argues
4f7638e 2019-07-22 14:57:36 Zhiting Lin fixed the account referesh error.
717ff8d 2019-06-26 16:25:37 Zhiting Lin update enable function.
52fa858 2019-06-12 15:54:50 Zhiting Lin update the dapp demo to fit the latest bycoin and byone
3bb6757 2019-04-02 11:21:14 Zhiting Lin update the readme file

Branches

Name Rev. Time Author Message
dependabot/npm_and_yarn/node-sass-7.0.0 96b49cf 2022-02-11 02:18:23 dependabot[bot] Bump node-sass from 4.11.0...
dependabot/npm_and_yarn/axios-0.21.1 234fea7 2021-01-05 16:41:34 dependabot[bot] Bump axios from 0.18.0 to ...
dependabot/npm_and_yarn/node-sass-4.13.1 ddf4020 2020-09-04 19:07:13 dependabot[bot] Bump node-sass from 4.11.0...
dependabot/npm_and_yarn/jquery-3.5.0 587eb93 2020-04-30 11:23:48 dependabot[bot] Bump jquery from 3.3.1 to ...
master ed6b30d 2019-07-22 15:34:48 Zhiting Lin update the account referesh...

README.md

Bytom-Dapp-Demo

What is this?

A simple deposit and profit bytom dapp demo, Bytom-Chrome-Extension needed before it can be used.

Setup

  • Install Node.js version 8 and the latest available npm@6.
  • Install dependencies: npm install.

Buffer Server

Before run all the project, you may need to set up you own bufferserver. Configure the proxy rules under the webpack.config.js.

Deploy Contract

Currently we are manually deploy the contract using the equity compiler tool, and configure the control program constants accordingly.

Contract configuration

Network and smart contract control program's constants configurations are stored under the contracts/configure.json.js file. You may edit the configure after an new control program is launched.

Dapp logic

Under the ./src/components/util/submitContract.js, you will see the basic and reusable logic, for developing a Dapp. Including the following steps: - list utxo from buffer server - create the custom contract transaction - lock utxo - call window.bytom.send_advanced_transaction to create the advanced Transaction - update balance if success.

Input and Output Object

Input

The first Input object must be spend utxo action, utxo will be selected according to the amount matches.

The second Spend Wallet Action, maybe needed if there is a exchanged.

input.push(spendUTXOAction(utxo))
input.push(spendWalletAction(amount, GetContractArgs().assetDeposited))

Output

Since the contract type and logic are different, building the unlock action may be different.

if amountDeposited < billAmount {
      lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
      lock amountDeposited of billAsset with saver
      lock billAmount-amountDeposited of billAsset with FixedLimitCollect(assetDeposited, totalAmountBill, totalAmountCapital, dueBlockHeight, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
    } else {
      lock amountDeposited of assetDeposited with FixedLimitProfit(billAsset, totalAmountBill, totalAmountCapital, expireBlockHeight, additionalBlockHeight, banker, bankerKey)
      lock billAmount of billAsset with saver
    }

Will need to be converted into

 if(amount < billAmount){
          output.push(controlProgramAction(amount, GetContractArgs().assetDeposited, GetContractArgs().profitProgram))
          output.push(controlAddressAction(amount, billAsset, address))
          output.push(controlProgramAction((BigNumber(billAmount).minus(BigNumber(amount))).toNumber(), billAsset, GetContractArgs().depositProgram))
        }else{
          output.push(controlProgramAction(amount, GetContractArgs().assetDeposited, GetContractArgs().profitProgram))
          output.push(controlAddressAction(billAmount, billAsset, address))
        }

Run the Project

Make sure the contracts are compiled, built the correct input output object and bufferserver is running.

Start the Webpack dev server.

npm start

Your server should now be running at http://127.0.0.1:8080

Building the Project

npm run build

Show on old repository browser