/xpower-hh

XPower Tokens

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

Main

XPower Token

XPower is a proof-of-work token, i.e. it can only be minted by providing a correct nonce (with a recent block-hash). It has a maximum supply of 0.930T × 1E64 XPOW. To be exact, the maximum supply of the XPOW token is:

9304721456570051417965525581055278309637766624917545324597787815844239114240

Installation

npm install

Help

npx hardhat help

Tasks

List accounts

npx hardhat accounts

Development

Clean

npx hardhat clean [--global]

ESLint

npx eslint '**/*.js' [--fix|--quiet]

Prettier

npx prettier '**/*.{json,md}' [--check|--write]

Solhint

npx solhint 'contracts/**/*.sol' [--fix|--quiet]

Compile

npx hardhat compile [--force|--quiet]

Testing

[REPORT_GAS=1] npx hardhat test [--no-compile] [...test-files]
npx hardhat coverage [...test-files]

Deployment

Start a localhost node

npx hardhat node

..which can be skipped, if another EVM compatible chain is available. In such a case, ensure to add the --network $NETWORK argument below. Possible networks are:

  • Hardhat's hardhat (for development and testing — default),
  • Hardhat's localhost (for development and testing — use with hardhat node),
  • Avalanche's local (requires an avalanchego instance),
  • Avalanche's fuji (for development and testing),
  • Avalache's mainnet,

..where the configuration details of each network can be found in hardhat.config.js.

Deploy smart contract(s)

npx hardhat run 'scripts/deploy.js' [--no-compile] [--network $NETWORK]

Mining & Minting

XPower tokens can be mined and minted at xpowermine.com, but you can also use a terminal based miner to do so. First, download the source code from this link, unpack the archive and then follow the instructions below:

https://github.com/xpowermine/xpower-hh/archive/refs/heads/main.zip

Installation & Build

npm install && npm run build

Environment Variables

cp .env-avalanche-main .env

..plus change in .env the MINT_ADDRESS to your own one; don't forget to set the corresponding MINT_ADDRESS_PK private key too. It's also possible to use the private key of a different address: That way the account of the beneficiary and the minting fee payer can be — for security purposes — separated.

MINT_ADDRESS=0x...    # beneficiary address (account to *receive* minted tokens)
MINT_ADDRESS_PK=0x... # minter address' private key (can be a different account)

Please, do NOT provide an address with a private key that contains massive amounts of AVAX! This account will only be used to auto-pay for some minting fees. Just ensure that there is enough — which you can afford to loose — but not more. Metamask users can for example add a new account, transfer a small amount of AVAX to it, and then export the private key from the account's details section.

Mining and Minting:

Usage: hardhat [GLOBAL OPTIONS] mine [--cache <BOOLEAN>] [--json <BOOLEAN>] [--level <INT>] [--mint <BOOLEAN>] [--nonce-bytes <INT>] [--refresh <BOOLEAN>] [--workers <INT>] [...tokens]

OPTIONS:

  --cache       cache block-hash (default: true)
  --json        json logs (default: false)
  --mint        auto-mint if possible (default: true)
  --mint-level  minimum minting threshold (default: 6)
  --nonce-bytes number of nonce bytes (default: 8)
  --refresh     refresh block-hash (default: false)
  --workers     number of mining processes (default: CPUs - 1)

POSITIONAL ARGUMENTS:

  tokens        xpow (default: ["xpow"])

mine: Mines for XPower tokens

Start mining and minting on the Avalanche mainnet for the XPower XPOW tokens (and optionally filter for the info messages only — requires the jq tool):

npx hardhat mine --network mainnet # | jq -rc 'select(.level=="info")|.message'
[INIT#0|ACK] block-hash=0x569...ade, timestamp=1651775584 => XPOW
[MINT#2|ACK] nonce=0x981...08d, block_hash=0x569...ade => 63 XPOW [279.289 H/ms]
...

..where you should see the [MINT] prefix, if minting for the nonce value has been successful. Further, to skip minting lower valued amounts you can use the mint-level option:

npx hardhat mine --network mainnet --mint-level 7 # | jq -rc '.message'
[MINT#2|ACK] nonce=0x626...3c4, block_hash=0x699...09d => 127 XPOW [609.415 H/ms]
...

..where you can stop mining with CTRL+C.

XPower and AVAX Balances

npx hardhat balances-xpow --network mainnet

..which lists all present accounts with XPower balances.

npx hardhat balances-avax --network mainnet

..which lists all present accounts with nano-AVAX balances.

Systemd Integration

Service installation

By default the service files assume the miner (repository) to be accessible at /opt/xpower-hh. If that is not the case, either provide a corresponding symbolic link or (if you cannot access /opt) modify the service files accordingly.

Create the systemd user directory:

mkdir -p ~/.config/systemd/user

Copy the systemd unit files to the user directory:

cp --update ./services/* ~/.config/systemd/user/

Reload the systemd user daemon:

systemctl --user daemon-reload

Enable the timer service (for e.g. mint-level=6):

systemctl enable --user xpow-miner@6.timer

..to ensure that mining starts upon a reboot (optional).

Service start

Start the timer service (to auto-[re]start – every hour – the miner service):

systemctl start --user xpow-miner@6.timer

List the installed timer services:

systemctl list-timers --user

Follow the journal of the miner service:

journalctl --user -fu xpow-miner@6.service

Service stop

Stop the timer service:

systemctl stop --user xpow-miner@6.timer

Stop the miner service:

systemctl stop --user xpow-miner@6.service

Service removal

Disable the timer service:

systemctl disable --user xpow-miner@6.timer

..to ensure that mining does not start upon a reboot.

Docker Integration

Pull the docker image of the miner:

docker pull xpowermine/miner

Or, build the docker image (for development — otherwise skip):

docker build -t xpowermine/miner .

Set the minter address and a private-key (can also be of a different address), plus the RPC end-point (optional):

export MINT_ADDRESS=0x..
export MINT_ADDRESS_PK=0x..
export AVAX_MAINNET_RPC=https://api.avax.network/ext/bc/C/rpc

Then, run a docker instance to start mining:

docker run --rm -ti \
-e MINT_ADDRESS="$MINT_ADDRESS" \
-e MINT_ADDRESS_PK="$MINT_ADDRESS_PK" \
-e AVAX_MAINNET_RPC="$AVAX_MAINNET_RPC" \
-e MINT_LEVEL=6 -e MINE_WORKERS=3 xpowermine/miner

Copyright

© 2023 Blackhan Software Ltd