Skip to content

WAX Random Number Generator Native Blockchain Service smart contract

License

Notifications You must be signed in to change notification settings

worldwide-asset-exchange/wax-orng

Repository files navigation

The WAX RNG Native Blockchain Service

  • Is open source and is a blockchain-native service that developers can easily integrate into their dApps.
  • Is based on the Signidice algorithm and RSA verification. Signidice was chosen for its excellent randomization and non-gameablity characteristics, in addition to yielding a cleaner workflow for dApp developers and being provably fair. RSA verification ensures uniqueness of the signature and removes the ability for the results to be manipulated (if any other type of signing algorithm were used, it would allow many valid signatures for the same signing_value which could result in manipulation).
  • Can easily be established as provably fair. The self-verifying WAX RNG Native Blockchain Service confirms that the RSA signature that comes back from the WAX RNG oracle is valid and authentic before being utilized by the dApp. When dApp customers can easily establish fairness, they have a higher degree of confidence in using the dApp.

For more information, check out the WAX blog.

Building the smart contract and its unit tests

  • Requirements

    • docker, installed and configured to run without sudo
    • make
  • Build and test

    # Build the smart contract
    make docker-build
    
    # Run tests
    npm install
    npm run test

Register bandwidth payer

WAX RNG allows dapps to pay for their own bandwidth, which can prevent your dapp from losing service during times of high activity on the rng contract. In the future, WAX will reduce the free bandwidth available for dapps, so it is a good idea to migrate to this to ensure your dapp is always up with respect to random number generation.

  1. create new permission name paybw and delegate it to oracle.wax@rngops
cleos set account permission payer111111 paybw '{"threshold":1,"keys":[],"accounts":[{"permission":{"actor":"oracle.wax","permission":"rngops"},"weight":1}]}' -p payer111111
  1. Allow paybw permission to call boost.wax noop
cleos set action permission payer111111 boost.wax noop paybw
  1. Dapp register for bandwith payer
cleos push action orng.wax setbwpayer '["dapp11111111", "payer111111"]' -p dapp11111111
  1. Payer accept to pay bandwidth
cleos push action orng.wax acceptbwpay '["dapp11111111", "payer111111", true]' -p payer111111

Allow list/Pay bandwidth for multiple contracts

To pay bandwidth for multiple contracts under one bandwdth paying account:

  1. Permission your payer account as in steps 1 and 2 in the previous section "Register bandwidth payer"

  2. Do multiple setbwpayer actions as in the previous section using the same payer account for each. The contract being allowed must make the request

cleos push action orng.wax setbwpayer '["dapp1", "payer111111"]' -p dapp1
cleos push action orng.wax setbwpayer '["dapp2", "payer111111"]' -p dapp2
cleos push action orng.wax setbwpayer '["dapp3", "payer111111"]' -p dapp2
  1. Payer must accept each set bandwidth payer request:
cleos push action orng.wax acceptbwpay '["dapp1", "payer111111", true]' -p payer111111
cleos push action orng.wax acceptbwpay '["dapp2", "payer111111", true]' -p payer111111
cleos push action orng.wax acceptbwpay '["dapp3", "payer111111", true]' -p payer111111

Register for error messages log

WAX RNG support developer to record error message to smart contract. Dapp need to delegate permission for oracle.wax, and has RAM to pay for store error message.

  1. create new permission name ornglog and delegate it to oracle.wax@rngops
cleos set account permission dapp11111111 ornglog '{"threshold":1,"keys":[],"accounts":[{"permission":{"actor":"oracle.wax","permission":"rngops"},"weight":1}]}' -p dapp11111111
  1. Allow ornglog permission to call orng.wax dapperror
cleos set action permission dapp11111111 orng.wax dapperror ornglog
  1. Set error log size

Last N error message will be stored on smart contract table

cleos push action orng.wax seterrorsize '["dapp11111111", 10]' -p dapp11111111
  1. Check for error message

Check table errorlog.a with scope is dapp contract name

cleos get table orng.wax dapp11111111 errorlog.a

License

MIT