feat: init (#1)

* chore: add package.json and package.lock to the project

* build: add truffle configuration for contract deployment

* feat: init swarm contracts and define migration script

* feat: init bash scripts that orchestrate docker containers

* fix: change auto-mining to progressing blockchain in order to satisfy bee ts check

* chore: add npm command definitions and downgrade openzeppelin for solc ^0.6.0

* build: set solc compiler configuration similar to the original swarm deployment

* chore: generate bee keys until 5 nodes

* refactor: import erc20 logic from openzeppelin and remove sw3 contract because cannot produce same bytecode

* chore: add trimmed single-swap-factory bytecode (without token address param)

* feat: deploy erc20 and single swap factory contracts that bee also accepts

* feat: bee.sh and blockchain.sh

* feat: add supply script to fund bee overlay addresses

* docs: amend README

* docs: fix bee start command

* fix: bee.sh datadir path

* docs: add network script to the usage description

* fix: solc compiler truffle config
This commit is contained in:
nugaon 2021-04-23 16:16:35 +02:00 committed by GitHub
parent 8bf781f84a
commit d38a2551a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 16358 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules/
build/

View File

@ -1,3 +1,44 @@
# Bee Factory
This project builds up a test environment with Bee clients and with a test blockchain.
The created environment is runnable on local machine as well.
All services run in `Docker` containers only.
Currently, the repository supports running Bee nodes up to 5 by default.
# Usage
You can setup the whole environment that Bee needs by running some scripts
Create the common Docker network for the environment with
```sh
$ ./scripts/network.sh
```
To start the blockchain, run the following command in the root directory of the project:
```sh
$ ./scripts/blockchain.sh
```
After that, it's possible to deploy Swarm smart contracts
```sh
$ npm run migrate:chequebook
```
Before you start the Bee nodes with the deployed Swap Factory, you have to fund your overlay addresses of your Bee nodes for the successful start.
The [supply.js](src/supply.js) script can fund the addresses which are defined in [bee-overlay-addresses.json](bee-overlay-addresses.json) file.
To run this script just execute
```sh
$ npm run supply
```
and the configured accounts will get 1 ether and 100 BZZ Token.
After all above went successfully you can start the Bee nodes.
```sh
$ ./scripts/bee.sh start --workers=4
```

View File

@ -0,0 +1,7 @@
[
"0x26234a2ad3ba8b398a762f279b792cfacd536a3f",
"0x8e3cb0148c5f39577fb815dc8c37795e30f5dcfa",
"0xed52b8ac9b1bc1e7f3fe46ea3a094fbaa8f6ccb4",
"0x119331b8074bd779fc5b96fe4d50947d31addfe4",
"0x102aaa556337d86e270010588d9fbd5ecaeebff8"
]

View File

@ -0,0 +1,3 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity =0.6.12;
import "@openzeppelin/contracts/presets/ERC20PresetMinterPauser.sol";

File diff suppressed because one or more lines are too long

35
migrations/1_initial.js Normal file
View File

@ -0,0 +1,35 @@
const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauser");
const FS = require('fs')
const Path = require('path')
function getSimpleSwapFactoryBin(tokenAddress) {
const simpleSwapFactoryBinPath = Path.join(__dirname, '..', 'contracts', 'SimpleSwapFactory.bytecode')
const baseBin = FS.readFileSync(simpleSwapFactoryBinPath, 'utf8').toString()
//remove 0x prefix
tokenAddress = tokenAddress.substring(2).toLowerCase().padStart(64, '0')
//add tokenaddress for param to the end of the bytecode
return baseBin + tokenAddress
}
async function createSimpleSwapFactoryContract(erc20ContractAddress, creatorAccount) {
const transaction = await web3.eth.sendTransaction({
data: getSimpleSwapFactoryBin(erc20ContractAddress),
gasLimit: 6721975,
gasPrice: web3.utils.toWei('10', 'gwei'),
from: creatorAccount
})
if(!transaction.status) {
console.error('SimpleSwapFactory contract creation Error', error)
throw new Error('Error happened at creating SimpleSwapFactory contract creation')
}
console.log(`SimpleSwapFactory contract creation was successful!\n`
+ `\tTransaction ID: ${transaction.transactionHash}\n`
+ `\tContract ID: ${transaction.contractAddress}`)
}
module.exports = function (deployer, network, accounts) {
deployer.deploy(ERC20PresetMinterPauser, "Swarm Token", "BZZ").then(async () => {
await createSimpleSwapFactoryContract(ERC20PresetMinterPauser.address, accounts[0])
});
};

15886
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "bee-factory",
"version": "0.0.1",
"description": "Setup Swarm Test Blockchain and arbitrary numbered Bee nodes",
"scripts": {
"compile:chequebook": "truffle compile",
"migrate:chequebook": "truffle migrate",
"test:chequebook": "truffle test",
"supply": "truffle exec src/supply.js"
},
"dependencies": {
"@openzeppelin/contracts": "^3.1.0",
"truffle": "^5.3.1"
},
"keywords": [
"swarm",
"ethereum-swarm",
"bee-factory"
],
"license": "BSD-3-Clause"
}

View File

@ -0,0 +1,2 @@
statestore
localstore

View File

@ -0,0 +1 @@
{"address":"33d0fff43ab18b6066d5a7c1a74852f0e5f1d549","crypto":{"cipher":"aes-128-ctr","ciphertext":"d0c9f5ba4d26f4c3a5ff75054a452ae06c4e7137456964286fb71ee4c39001c9","cipherparams":{"iv":"d53f8d37effe8eaf9215b614194c6336"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"676530f1559492f872a030a68044434c62b4e4ccc45834cfdd93ac7ae5bf3eaf"},"mac":"b4f0c223f23a028d0070a0657ac2f394c17d7501b23d17ffc9da0e0eb4a468f7"},"version":3}

View File

@ -0,0 +1 @@
{"address":"4f86d2a325b5484114c746f4f62567c3307c4609","crypto":{"cipher":"aes-128-ctr","ciphertext":"a965f1be20058860f1c463de2f7fd14b168f0eacf015dcfa009c5e8fff6f943f","cipherparams":{"iv":"51379174047cfdf82a4267e4f33de608"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"18779e1a157feb172aee97c53f8c2302b74127289b10466372cd3971a66ab28e"},"mac":"6d052ca5750d5f35b7d3798484c414bcc8ad8f8b3ed5309e78a80974a55d1a9e"},"version":3}

View File

@ -0,0 +1 @@
{"address":"26234a2ad3ba8b398a762f279b792cfacd536a3f","crypto":{"cipher":"aes-128-ctr","ciphertext":"fffb7140c654126abb77a8c2f876d6be0e15213a823b1bb69b061bc015b4dbb1","cipherparams":{"iv":"ee1fd715ab558a569ca47707c5cc0dda"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"4d959d634ced780cd51217d654b2b4c776118a4bdfa91c6899ab08348ce2d6b0"},"mac":"b3ebd4561b62ced24a4b059fcbc4106690fb25bb3774bff323dcdfdf61661c6c"},"version":3}

View File

@ -0,0 +1,2 @@
statestore
localstore

View File

@ -0,0 +1 @@
{"address":"a073d821229ab0ec33a4ca823a48328171f30dfc","crypto":{"cipher":"aes-128-ctr","ciphertext":"e73ed3fabee776bd9151f7f7594479f969b58941a2bbdeb7534c4897211b0e51","cipherparams":{"iv":"2d376deaad1c949dc7eb49af4521a6e1"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"bbd2a1f20411edd89c7ca4eabad6fc4deb23edadfdbba94067ec6b30f68bd313"},"mac":"20c5d9d0ec69877d8087f91056cce750a624eae094d05a18428b36ce36549603"},"version":3}

View File

@ -0,0 +1 @@
{"address":"172c9699e88d18b9c4bb91bd76cfba83c021d341","crypto":{"cipher":"aes-128-ctr","ciphertext":"81de20a914b615f102e660283402f8481fb37db55916351fa7ec4d73be167f20","cipherparams":{"iv":"054a833aced209f8435cb7ed6153832d"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"2395d56b6397fbe4c76bd74f5b312b4b1e7e4cddc5b86986eee411cb98b1789c"},"mac":"0342ec20f4d1ac86734527fc28015cd84a1bcfbf621c0e4fcefecf8f98ccc206"},"version":3}

View File

@ -0,0 +1 @@
{"address":"8e3cb0148c5f39577fb815dc8c37795e30f5dcfa","crypto":{"cipher":"aes-128-ctr","ciphertext":"c3c64c5b4371a59d87a4883b499a5622774511d4421298c0e8849acb64d1111e","cipherparams":{"iv":"e31330130d3045f1b2614e819a4c06f6"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"25be64863839d78f078ff7c874412c682dc2fc290138ce749ac3bdc7ed267b5a"},"mac":"c8ecf497e8afec977de05b2c514194aa329eca701ca559520a0d4545591e3d2f"},"version":3}

View File

@ -0,0 +1,2 @@
statestore
localstore

View File

@ -0,0 +1 @@
{"address":"d31ef99de0a34356f3bd356617f332fddc948232","crypto":{"cipher":"aes-128-ctr","ciphertext":"022c6805e9b8e7e499046d26cba90e90fd37c46cf9ee21c1aff15f50a2a8d3c6","cipherparams":{"iv":"d4d96fb0ee5a1df7534fdf702c7733ca"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"a0f1e03f9f73c5e7607c4b8c68242e0a7c705e40e9193952a209d4ed9b204a7f"},"mac":"ecea407aa1c76be3fb0254aecf92cba256dfd8f9f1eca904415f7c8877be8452"},"version":3}

View File

@ -0,0 +1 @@
{"address":"7618b0084b6b274d5140049df8b3ae423626fcac","crypto":{"cipher":"aes-128-ctr","ciphertext":"19a117a9c17ef72f2b2fb3642f6a07bafda0487d58428fab05dc175976dbd0b3","cipherparams":{"iv":"10d2d1bcf0281b0cac32b2e2a84ea701"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"e504f0e661803766a6e0841345987ec112edbda80569d9f912a3618d8c9fc904"},"mac":"682392951017ce45ea64a2e225dcd5cae129b78d6f34602123f3746bd0db5168"},"version":3}

View File

@ -0,0 +1 @@
{"address":"ed52b8ac9b1bc1e7f3fe46ea3a094fbaa8f6ccb4","crypto":{"cipher":"aes-128-ctr","ciphertext":"439cd5a2ebe1b37417708dff4f494eccef49ca8bf90caf28fb941fe964e3826d","cipherparams":{"iv":"0ea3e06704e1842ab7a9756a18ac4c27"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"54774845914adc48df887864a1935e97de333045021c27eb0561cacfd65eed78"},"mac":"40de101683baa8acd76a3577211a6827e330a81d7a7e28af9c5872e2ea855b6a"},"version":3}

View File

@ -0,0 +1,2 @@
statestore
localstore

View File

@ -0,0 +1 @@
{"address":"906ab9aede7032f8e1049d057355904f8b9e15bc","crypto":{"cipher":"aes-128-ctr","ciphertext":"32bf4178f95c3554ff1b99c0f8a00458e0b6e1b017cd18dbac8e08d620687c33","cipherparams":{"iv":"66e35d850dfc6ff0bbfb67e8ce7d11c7"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"dd0a67dd5feb9f4c538fcfdcdfa04b48d229a9d0222513a14ddd6b92083d07f1"},"mac":"7bc40b0ea294d77bdcff48dab0d83f02302ae1d73154be132f017cf84c30ac6f"},"version":3}

View File

@ -0,0 +1 @@
{"address":"b531efea3a09881d97e6526ff5ac2647fb8d8fb7","crypto":{"cipher":"aes-128-ctr","ciphertext":"a6e3791bf08c4c49531ebe24156201b2654c1b27c4fdf022c8281197736e3b4d","cipherparams":{"iv":"e6a73c1b91f81dff9031f64edce1b611"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"31acaa07698ca075e9da7fc039087d58991cf719d69d547e9b87a8ae9f8da193"},"mac":"9d04640df0f569275f99c70e20d1221b6dda50f387824409ff40c68efc98289c"},"version":3}

View File

@ -0,0 +1 @@
{"address":"119331b8074bd779fc5b96fe4d50947d31addfe4","crypto":{"cipher":"aes-128-ctr","ciphertext":"8ad055c629e5ec8731a879a72c994a4813c1fcc512ed2630c287dfd13e00aa1e","cipherparams":{"iv":"602457307b87eb967542f89d90ab6116"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"fcb50fe029550bce3c8d33db67bd8a48bd51d74b32b13e8e771bb158a9083bf3"},"mac":"e3e590561691f13c12d78c5eadb7adb106cb32e32af6f07f44a8d0188bda0043"},"version":3}

View File

@ -0,0 +1,2 @@
statestore
localstore

View File

@ -0,0 +1 @@
{"address":"554b4e35700ba8118b74b0c3d006b46b4322d37c","crypto":{"cipher":"aes-128-ctr","ciphertext":"b8b2431700b19fffaab5b5a3afae2f26610617c30db4d85a10eeebc6c2c1e2ed","cipherparams":{"iv":"2e5228d8b2cebf36989f3e8738034ce4"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"cde5530d1e339e03087f6bcc17e4380c685df529307caeb66e2437bc455d7f09"},"mac":"80ae4166ded63aa4c8f77227e6c200c11621ee6ee2a0f2370e17fefd61776160"},"version":3}

View File

@ -0,0 +1 @@
{"address":"e629ba730a0ac0d6efc6a90957af96ca12be257d","crypto":{"cipher":"aes-128-ctr","ciphertext":"5878029af23f16cb63d4a4d9d90a40fb53921aa8a7639c0e35f4ad835ae7299c","cipherparams":{"iv":"b3d8e4e9d0366ee572e8ead3b5c7d05b"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"78b7beef4f18d6cc4cfb751e7a34f4bdd837e25f0fa2ad0c0f0f437368eb0566"},"mac":"4ea8a7787dc1a055af8ecfaded2d2d3fd45cd45d626fbcb3f5dadbda3bd5588e"},"version":3}

View File

@ -0,0 +1 @@
{"address":"102aaa556337d86e270010588d9fbd5ecaeebff8","crypto":{"cipher":"aes-128-ctr","ciphertext":"0794b7bfb7f68df0abb0a729c1774fa5821fb1811cd04c48e8644d6743b20307","cipherparams":{"iv":"533434567172fb0c3cf6c1c5a94621cd"},"kdf":"scrypt","kdfparams":{"n":32768,"r":8,"p":1,"dklen":32,"salt":"70fa8ec6fce2fc2adcb14ecef2945dd49592c27605baa45f7e051845b2f04813"},"mac":"4f5ef03dcf39e7b6e2c3d3ffaca260a576968f64a2026b1b8749f430b25217a0"},"version":3}

199
scripts/bee.sh Executable file
View File

@ -0,0 +1,199 @@
#!/bin/bash
echoerr() { if [[ $QUIET -ne 1 ]] ; then echo "$@" 1>&2; fi }
usage() {
cat << USAGE >&2
USAGE:
$ bee.sh [COMMAND] [PARAMETERS]
COMMANDS:
start create Bee cluster with the given parameters
stop stop Bee cluster
PARAMETERS:
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
--workers=number all Bee nodes in the test environment. Default is 4.
--port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
1. 1633:1635
2. 11633:11635
3. 21633:21635 (...)
number represents the nodes number to map from. Default is 4.
--password=string password for Bee client(s).
--version=x.y.z used version of Bee client.
USAGE
exit 1
}
stop() {
echo "Stop following containers:"
docker container stop $QUEEN_CONTAINER_NAME;
WORKER_NAMES=`docker container ls -f name="$WORKER_CONTAINER_NAME*" --format "{{.Names}}"`
for WORKER_NAME in $WORKER_NAMES; do
docker container stop "$WORKER_NAME"
done
trap - SIGINT
exit 0;
}
fetch_queen_underlay_addr() {
if [[ ! -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then return; fi
while : ; do
QUEEN_UNDERLAY_ADDRESS=$(curl -s localhost:1635/addresses | python -mjson.tool 2>&1 | grep "/ip4/" | awk '!/127.0.0.1/' | xargs)
if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then
echo "Waiting for the Queen initialization..."
sleep 5
else
break;
fi
done
}
log_queen() {
trap stop SIGINT
docker logs --tail 25 -f $QUEEN_CONTAINER_NAME
}
# Init variables
EPHEMERAL=false
WORKERS=4
QUEEN_CONTAINER_NAME="swarm-test-queen"
WORKER_CONTAINER_NAME="swarm-test-worker"
QUEEN_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$QUEEN_CONTAINER_NAME`
BEE_VERSION="0.5.3"
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
BEE_PASSWORD="password"
QUEEN_BOOTNODE=""
PORT_MAPS=2
NETWORK="swarm-test-network"
SWAP=true
SWAP_FACTORY_ADDRESS="0x5b1869D9A4C187F2EAa108f3062412ecf0526b24"
MY_PATH=`dirname "$0"` # relative
MY_PATH=`( cd "$MY_PATH" && pwd )` # absolutized and normalized
INIT_ROOT_DATA_DIR="$MY_PATH/bee-data-dirs"
# Decide script action
case "$1" in
start)
shift 1
;;
stop)
stop
;;
*)
echoerr "Unknown command: $1"
usage
;;
esac
# Alter variables from flags
while [ $# -gt 0 ]
do
case "$1" in
--ephemeral)
EPHEMERAL=true
shift 1
;;
--workers=*)
WORKERS=${1#*=}
shift 1
;;
--password=*)
BEE_PASSWORD="${1#*=}"
shift 1
;;
--version=*)
BEE_VERSION="${1#*=}"
BEE_IMAGE="ethersphere/bee:$BEE_VERSION"
shift 1
;;
--port-maps=*)
PORT_MAPS="${1#*=}"
shift 1
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if $EPHEMERAL ; then
EXTRA_DOCKER_PARAMS=" --rm"
fi
# Start Bee Queen
if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
EXTRA_QUEEN_PARAMS=""
if [ $PORT_MAPS -ge 1 ] ; then
EXTRA_QUEEN_PARAMS=" -p 127.0.0.1:1633-1635:1633-1635"
fi
echo "start Bee Queen process"
docker run \
-d \
--network=$NETWORK \
--name $QUEEN_CONTAINER_NAME \
-v $INIT_ROOT_DATA_DIR/$QUEEN_CONTAINER_NAME:/home/bee/.bee \
$EXTRA_DOCKER_PARAMS \
$EXTRA_QUEEN_PARAMS \
$BEE_IMAGE \
start \
--password $BEE_PASSWORD \
--bootnode=$QUEEN_BOOTNODE \
--debug-api-enable \
--verbosity=4 \
--swap-enable=$SWAP \
--swap-endpoint="http://swarm-test-blockchain:9545" \
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
--welcome-message="You have found the queen of the beehive..." \
--cors-allowed-origins="*"
else
docker start "$QUEEN_CONTAINER_IN_DOCKER"
fi
# Start Bee workers
for i in $(seq 1 1 $WORKERS); do
WORKER_NAME="$WORKER_CONTAINER_NAME-$i"
WORKER_CONTAINER_IN_DOCKER=`docker container ls -qaf name=$WORKER_NAME`
if [ -z "$WORKER_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
# fetch queen underlay address
fetch_queen_underlay_addr
# construct additional params
EXTRA_WORKER_PARAMS=""
if [ $PORT_MAPS -gt $i ] ; then
PORT_START=$((1633+(10000*$i)))
PORT_END=$(($PORT_START + 2))
EXTRA_WORKER_PARAMS=" -p 127.0.0.1:$PORT_START-$PORT_END:1633-1635"
fi
# run docker container
echo "start Bee worker $i process"
docker run \
-d \
--network=$NETWORK \
--name $WORKER_NAME \
-v $INIT_ROOT_DATA_DIR/$WORKER_NAME:/home/bee/.bee \
$EXTRA_DOCKER_PARAMS \
$EXTRA_WORKER_PARAMS \
$BEE_IMAGE \
start \
--password $BEE_PASSWORD \
--bootnode="$QUEEN_UNDERLAY_ADDRESS" \
--debug-api-enable \
--swap-enable=$SWAP \
--swap-endpoint="http://swarm-test-blockchain:9545" \
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
--welcome-message="I'm just Bee worker ${i} in the beehive." \
--cors-allowed-origins="*"
else
docker start "$WORKER_CONTAINER_IN_DOCKER"
fi
done
# log Bee Queen
log_queen

17
scripts/blockchain.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
NAME=swarm-test-blockchain
CONTAINER_IN_DOCKER=`docker container ls -qaf name=$NAME`
if [ -z "$CONTAINER_IN_DOCKER" ]; then
# necessary "-b 1" because anyway the Bee throws Error: waiting backend sync: Post "http://swarm-test-blockchain:9545": EOF
docker run \
-p 127.0.0.1:9545:9545 \
--network swarm-test-network \
--name swarm-test-blockchain -d \
trufflesuite/ganache-cli ganache-cli \
-d -i 4020 -h 0.0.0.0 -p 9545 \
-b 1 \
--db swarm-testchain --gasLimit 6721975
else
docker start $NAME
fi

6
scripts/network.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
NETWORK="swarm-test-network"
if ! `docker network inspect $NETWORK > /dev/null` ; then
echo "Creating $NETWORK..."
docker network create swarm-test-network
fi

86
src/supply.js Normal file
View File

@ -0,0 +1,86 @@
const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauser");
const beeAddresses = require('../bee-overlay-addresses.json')
function getRawTokenAmount(amount, decimals = 18) {
amount = web3.utils.toBN(amount)
const rawAmount = amount.mul(web3.utils.toBN(10).pow(web3.utils.toBN(decimals)))
return rawAmount
}
/** Supply given address with Ether */
async function supplyEther(recepientAddress, supplierAddress, etherAmount = "1") {
const transaction = await web3.eth.sendTransaction({
gasLimit: 6721975,
gasPrice: web3.utils.toWei('10', 'gwei'),
value: web3.utils.toWei(etherAmount),
from: supplierAddress,
to: recepientAddress
})
if(!transaction.status) {
console.error('Supply Ether Error', transaction)
throw new Error(`Error happened at supplying address ${recepientAddress} from account ${supplierAddress}`)
}
console.log(`Supplying address ${recepientAddress} with Ether from account ${supplierAddress} was successful! \n`
+ `\tGiven Ether Amount: ${etherAmount}\n`
+ `\tTransaction ID: ${transaction.transactionHash}`
)
console.log('-'.repeat(process.stdout.columns))
}
/** Supply given address with the given Token amount */
async function mintToken(recepientAddress, supplierAddress, tokenAddress, tokenAmount = "100") {
const instance = await ERC20PresetMinterPauser.at(tokenAddress)
const rawTokenAmount = getRawTokenAmount(tokenAmount)
const transaction = await instance.mint(
recepientAddress,
rawTokenAmount,
{
from: supplierAddress,
gasLimit: 6721975,
}
)
if(!transaction.receipt.status) {
console.error('Supply Token Error', transaction)
throw new Error(`Error happened at supplying address ${recepientAddress} from account ${supplierAddress}`)
}
console.log(`Supplying address ${recepientAddress} with Token from account ${supplierAddress} was successful! \n`
+ `\tGiven Token Amount: ${tokenAmount}\n`
+ `\tTransaction ID: ${transaction.tx}`,
)
console.log('-'.repeat(process.stdout.columns))
}
/** Supply ERC20 tokens to all configured Bee client overlay addresses */
async function supplyTokenForBees(supplierAddress, erc20ContractAddress) {
const txPromises = []
console.log(`Supply ERC20 tokens (${erc20ContractAddress}) to the configured Bee addresses`)
console.log('='.repeat(process.stdout.columns))
for(const beeAddress of beeAddresses) {
txPromises.push(mintToken(beeAddress, supplierAddress, erc20ContractAddress))
}
return Promise.all(txPromises)
}
/** Supply ether to all configured Bee client overlay addresses */
async function supplyEtherForBees(supplierAddress) {
const txPromises = []
console.log('Supply Ether to the configured Bee addresses')
console.log('='.repeat(process.stdout.columns))
for(const beeAddress of beeAddresses) {
txPromises.push(supplyEther(beeAddress, supplierAddress))
}
return Promise.all(txPromises)
}
module.exports = (async function(callback) {
const accounts = await web3.eth.getAccounts()
await supplyTokenForBees(accounts[0], ERC20PresetMinterPauser.address)
await supplyEtherForBees(accounts[0])
callback()
});

29
truffle-config.js Normal file
View File

@ -0,0 +1,29 @@
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 9545,
network_id: "4020",
gasPrice: "10000000000", //10 gwei
}
},
compilers: {
solc: {
version: "0.6.12", // Fetch exact version from solc-bin (default: truffle's version)
docker: true,
settings: {
optimizer: {
enabled: true,
runs: 200 // Optimize for how many times you intend to run the code
},
evmVersion: "istanbul"
}
}
},
db: {
enabled: true
}
};