Build the future of DeFi Gaming
bepro-js is available as npm package.
# with npm
npm i bepro-js
# with yarn
yarn add bepro-js
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
For tests, we use Ganache.
Once installed, you can:
# Boot it up
yarn ganache:start
# Run the tests
yarn test
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
Full API docs can be found at https://bepronetwork.github.io/bepro-js/
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();
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 },
});
/* 4 - Assert all object data */
await staking.__assert();
await stakingTest.__assert();
/* or deploy the contract*/
await staking.deploy();
await stakingTest.deploy();
/* 5 - Access other Methods */
await staking.availableTokens();
await stakingTest.availableTokens();
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.
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:
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...' },
);
Contributions are welcomed but we ask to read existing code guidelines, especially for the code format. Please review Contributor guidelines
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