• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    JavaScript
  • Created almost 4 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The repository contains a comprehensive documentation of the bepro.network ecosystem as a javascript framework. If you are new to BEPRO, you might want to check out the Website Overview or our public "Start Building" Page.

alt tag

Python Build Status Dependencies GitHub issues Contributions welcome License

Introductions

Build the future of DeFi Gaming

Installation

bepro-js is available as npm package.

# with npm
npm i bepro-js

# with yarn
yarn add bepro-js

Local Development

Requirements

Python 2

For Linux:

# Install it via bash terminal globally
sudo apt install python2

# Check the installed version.
# Must shown Python 2.7.18rc1 on terminal to the install be OK
python2 --version

# Verify Python 2.7 path
ls /usr/bin/python*

# Set Python 2 as alternative 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1

# Confirm Python 2 as alternative priority 1
sudo update-alternatives --config python

# On the working directory, run the cmd below to set Python locally
npm config set python python

# Confirm the procedure.
# Must show valid Python version on terminal if OK
python --version

For other systems please follow the appropriate steps.

Node.js 16

Install via NVM:

# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash

# Install recommended Node.js version for bepro-js
nvm install lts/gallium

# Set it on the working directory
nvm alias default lts/gallium

# Use the settled as default
nvm use default

# Confirm the procedure.
# Must show valid Node-js version on terminal if OK
node --version
Yarn 1
npm install -g yarn

Or check alternative install methods.

Running commands

The following is a set of the commands you most likely will need. For details on these or to check all relevant Node.js tasks, please reference the scripts section of package.json.

# Install and update dependencies
yarn

# Start watch for rebuild on file changes
yarn start

# Build from src
yarn build

Local Ethereum Client

For tests, we use Ganache.

Once installed, you can:

# Boot it up
yarn ganache:start

# Run the tests
yarn test

Docker support

Requirements

Docker 19.03.3+
sudo curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh

Notice: If you already have Docker installed, this script can cause trouble. If you installed the current Docker package using this script, run it again to update Docker.

Or use official installation instructions: Mac, Windows, Ubuntu, Other.

Docker Compose 1.19.0+
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose

For Mac or Windows take a look on: official guides.

Running containers

You can use docker-compose directly, or the nifty make that comes bundled.

# Build images
make build

# Starting containers in background:
make up

# Start npm watch:
make watch

# Run tests
make test

# Stop containers
make down

# Using docker-compose instead of make
docker-compose up

Documentation

Full API docs can be found at https://bepronetwork.github.io/bepro-js/

Usage

Initialization

Via WEB3_LINK from any Web3 Provider

Note: WEB3_LINK should be get from Infura/Quicknode or any other Web3 Provider - ETH, BSC, Moonbeam and others are supported

import {
    Application, DexStorage, ERC20Contract, StakingContract,
    ERC20TokenLock, ERC721Collectibles, ERC721Standard
} from 'bepro-js';

/* 1.1 - Instantiate the App for Metamask functionality (MAINNET) */
const app = new Application({
  opt: { web3Connection: 'WEB3_LINK' },
});

/* 1.2 - Instantiate StakingContract Object or any other in a similar way (Staking, ERC20 etc..) */
// - MAINNET
const staking = new StakingContract({
  contractAddress: null, /* Contract Address (optional) */
  opt: { web3Connection: 'WEB3_LINK' },
});

// - TEST net e.g. Rinkeby
const stakingTest = new StakingContract({
  test: true,
  contractAddress: null, /* Contract Address (optional) */
});

/* 2 - Connect the App/Contract to the Metamask Web3 Injected wallet*/
await app.login();
await staking.login();
/* or instantiate with the provided web3Connection, for tests it was already done at object creation */
await app.start();
await staking.start();

Via leveraged Web3 Provider

Application can be initialized with a web3 provider directly, but all connection login is assumed to be on the consumer side in this case; i.e. no need to call start() or login(), that logic should be handled separately within the provider itself or by the consumer.

// Use Metamask's provider, could be any other compatible Web3 Provider object from any other lib
const app = new Application({
  opt: { provider: window.ethereum },
});

Asserting and Deploying contracts

/* 4 - Assert all object data */
await staking.__assert();
await stakingTest.__assert();
/* or deploy the contract*/
await staking.deploy();
await stakingTest.deploy();

Accessing methods

/* 5 - Access other Methods */
await staking.availableTokens();
await stakingTest.availableTokens();

Transaction options

Most contract send methods (those that act on and potentially alter the state of the blockchain) can be passed an optional argument, taking the form of an object with several properties that control the transaction.

__sendTx() details for internal development

call instead of send

If you send a truthy property call, you are signaling that this transaction is a read-only call to the blockchain, and will thus not incur in any gas fees, value transaction, or even needs to be signed by a specific account.

await this.__sendTx(
  this.getContract().methods.someMethod(),
  { call: true },
);

value

Likewise to above, if a transaction is to have an intrinsic value, this is also passed through this object.

await this.__sendTx(
  this.getContract().methods.someMethod(),
  { value: someValue },
);

Gas Fees

Transaction fees are automatically calculated via web3's own estimation methods.

In order to overestimate and avoid out-of-gas transaction errors if necessary, we can pass a second argument with certain parameters to most Contract methods that involve send transactions (those requiring gas):

await staking.subscribeProduct(
  { address, product_id, amount },
  {
    gasAmount: 201654, // override the estimated gas fee for this method
    gasFactor: 1.2, // applied to every calculated or given gas amount, including the gasAmount from this object if passed
    gasPrice: '5000000000', // override the network's default gas price
  },
);

In particular, gasFactor is a parameter that can be passed when instantiating the contract, so that gas estimations for every method called on that contract instance will have that factor applied:

const staking = new StakingContract({
  contractAddress,
  gasFactor: 1.25 // default 1
  opt: { provider },
});

// The following will have a gasFactor of 1.25
await staking.subscribeProduct({ address, product_id, amount });

// We can still override it per-method, and pass other parameters as well.
await staking.subscribeProduct(
  { address, product_id, amount },
  {
    gasAmount: 201654,
    gasFactor: 1.2,
  },
);

Estimated gas fees leverage the following web3 functionalities:

Transaction signer

You can get all accounts (wallet addressed) managed by the current wallet provider through:

await app.getAccounts();
// => [ '0xAbA...', '0xCdD...', '0xEfE...', ... ]

By default all transactions will be signed by the first account, which is considered currently active. Any transaction on any contract, including deployment, can be signed by any of the connected accounts:

await staking.deploy({ from: '0xCdC...' });

await staking.subscribeProduct(
  { address, product_id, amount },
  { from: '0xCdC...' },
);

Contribution

Contributions are welcomed but we ask to read existing code guidelines, especially for the code format. Please review Contributor guidelines

License

MIT

Notes

The usage of ETH in all methods or params means using the native currency of that blockchain, example BSC in Binance Chain would still be nominated as ETH