The project provides for the accretive minting and issuance of fungible utility tokens utilized by a dApp according to the dApp’s award system. Instead of tokens being pre-mined (minting all token supply at the moment the token is created) or issued on a time-based automated schedule regardless of token demand or use (as in PoW or PoS block rewards), an accretive utility token issuance model accurately reflects the dApp’s utility while providing users a method to acquire utility tokens based on their skill without regard to their economic power. It also proposes and implements a compensation framework that is intended to equitably and transparently reward developers in direct proportion to the utility of their dApp by transferring them 1/8th of the newly minted tokens, with the remainder going to the winner of the award event. As a vehicle for the accretive utility token (AUT) issuance model, I have built a simple raffle contract to demonstrate how award events can be created and managed by the developer/contract deployer, with the number of raffle participants equal to the number of tokens minted for that raffle. The raffle winner gets 7/8ths of the new tokens while the developer gets 1/8th.
The docs folder contains the following files:
- Node
- NPM (version 5.2 or above - if you are using an earlier version you need to install NPX as well)
- Truffle
- Ganache-cli
- web3
- Metamask
- from the terminal, create a new directory for this project - eg
mkdir AUTRaffle
- from inside that directory, run
truffle init
- in the contracts folder, create a new file titled "AUTRaffle.sol" and copy the solidity code from this repository
- in the migrations folder, create a new file titled "2_deploy_contracts.js" and the js code from this repository
- in the test folder, create a new file titled "AUTRaffleTest.js" and copy the js code from this repository
- replace the files "truffle.js" and "truffle-config.js" with the same named files in this repository, or simply edit your files to match the code here
- install the OpenZeppelin libraries via
npm install -E openzeppelin-solidity
- run
ganache-cli
- in a new terminal tab in the same directory, run
truffle compile
- run
truffle migrate
- copy the contract address - run
truffle test
- in the terminal, from a root project directory
npx create-react-app "autraffle-react-app"
cd autraffle-react-app
- install web3 by running
npm install web3
- copy “App.js” code from the /react-app folder in this repository into the existing "App.js" in the /src folder
- copy “AUTRaffle.js” and "web3.js" from the same folder into /src
- run
ganache-cli
- log out of your metamask account and then import the seed words generated by ganache into metamask
- in metamask, switch networks to Localhost 8545
- in a new terminal window, navigate to the AUTRaffle directory and run
truffle migrate --reset
- copy “AUTRaffle.json” from /build/contracts of your AUTRaffle directory into the /src file of autraffle-react-app
- in “AUTRaffle.js”, copy the deployed contract address of AUTRaffle into the address variable placeholder and save the file
- in the terminal, from the autraffle-react-app directory launch the dev server dApp via
npm run start
- each time you click a button to interact with the dApp, you may need to click the Metamask icon to open the signing window - you may also need to refresh the page if you wish to send transactions after switching between Metamask accounts NOTE: because every completed raffle requires an owner and at least two entrants, you will need to access at least three Metamask accounts to fully interact with and test the dApp - you can access additional ganache-created test accounts in metamask by clicking the circular identicon in the top right and clicking "Create Account"
- at the Remix browser, copy the code from "FlattenedAUTRaffle.sol" into a new window
- copy the seed words from ganache-cli into a new metamask account import
- switch metamask networks to Localhost 8545
- from the "Run" tab in Remix, select Injected Web3 environment - it should then show the first account created by ganache-cli that should also be loaded in metamask (NOTE: to access accounts after the account at index [0], click create account in metamask - it should give you the next account created by ganache-cli)
- below that, paste the contract address copied from running
truffle migrate
into the form and click "At Address" - this should generate a new Deployed Contract of "AUTRaffle" - click the arrow to interact with the contract - to switch between metamask accounts, you may need to refresh the page and redirect to the deployed contract by repeating the step above
- using the javascript VM environment, Deploy a copy of AUTRaffle
- open the instance that appears in "Deployed Contracts" below and interact with the contract to test its functions
- obtain rinkeby testnet ether from a metamask address - you can get some here
- at the Remix browser, switch to the injected web3 environment
- under the "Run" tab, copy the following into the form and click the "At Address" blue button
0xCF1F697736eC8F723Fb526e0c3AA4B654C1A6443
- this is an instance of the contract that has been deployed to the Rinkeby testnet - open the instance that appears in "Deployed Contracts" below and interact with the contract to test its functions - feel free to send me an email at [email protected] if you'd like me to open a raffle or pick a winner
- A raffle organizer deploys the contract, becomes its owner via the constructor and sends a transaction via the openEvent function to open a new raffle.
- Upon deployment, ERC20-compliant RaffleTokens (RFT) are instantiated with a totalSupply of 0
- Participants enter the raffle by sending a transaction via the "enter" function
- Once there are at least two entrants in the raffle, the owner can call "pickWinner" which pseudorandomly chooses a winner of the raffle, closes the raffle to new entrants and clears the array of current entrants.
- At the moment that a winner is picked, 1 RFT is minted for each entrant, so a minimum of 2 RFT tokens per raffle.
- Also at that moment, the winner is transferred 7/8ths of the minted RFT, and the owner who deployed the contract is transferred 1/8th of the minted RFT
- Token balances are stored on the blockchain, and the owner may open a new raffle from the same deployed contract by repeating the first step.
This contract uses the following OpenZeppelin libraries: