Proof of Work Distribution
Distributing sFUEL through Proof-of-Work is a two-step process where the first step is optional depending on your SKALE Chain.
|If you are building on a SKALE Hub or Chaos Testnet, checkout the deployed contracts and skip to Step II.|
If you are on a dedicated SKALE Chain and have not deployed a sFUEL Distribution smart contract, yet, proceed with Step I.
Start by cloning (and optionally forking) the GitHub repository:
git clone https://github.com/Dirt-Road-Develompent/sfuel-distribution-contract && cd sfuel-distribution-contract
After entering into the root of the directory run the setup script:
chmod +x ./setup.sh && ./setup.sh
This will install npm packages, add the Open Zeppelin smart contracts package, and create a .env file in the root of project.
The next step is to setup the environment. Open the .env file which looks like this:
# Private Key - DO NOT SHARE - Should NOT start with 0x DEPLOYER_PRIVATE_KEY= # SKALE Chain RPC RPC_URL= # Decimal Form CHAIN_ID= # Blockscout -> Browser Url + /api API_URL= # Blockscout BROWSER_URL=
and fill in the all the values. The final result should look like this:
# Private Key - DO NOT SHARE - Should NOT start with 0x DEPLOYER_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000 # SKALE Chain RPC RPC_URL=https://mainnet.skalenodes.com/v1/some-amazing-schain-name # Decimal Form CHAIN_ID=11111111111 # Blockscout -> Browser Url + /api API_URL=https://some-amazing-schain-name.explorer.mainnet.skalenodes.com/api # Blockscout BROWSER_URL=https://some-amazing-schain-name.explorer.mainnet.skalenodes.com
|The private key added is linked to an Ethereum Address. That Ethereum Address must have Deployer Role — see SKALE Chain Access Control — and at least as much sFUEL as defined in the deployment config here. Deployment will fail without confirming these.|
If the deployer address does not have DEPLOYER_ROLE, the transaction will fail with an error on the explorer that says:
Error: Out of Gas
With everything setup, you can deploy the contract by running:
chmod +x ./deploy_secure.sh && ./deploy_secure.sh
The contract should deploy in a few seconds. Once deployed, the contract will automatically begin to verify itself on the block explorer. Do not interrupt this process if you want the contract verified. Make sure to save this contract address, you will need it for Step II of this recipe.
Step 2 of this recipe uses Next.Js, Wagmi, Rainbowkit, and Proof of Work to distribute sFUEL to new users of your dApp.
Start by cloning the recipe to your local machine by running:
git clone -b starter-pow-distribution-frontend https://github.com/skalenetwork/recipes.git && cd recipes/next.js
Once cloned and in the next.js directory, run:
to install the necessary packages.
Now, to run the project on the Calypso NFT Hub testnet you can run:
npm run dev
in your terminal and navigate to localhost on port 3000. Connecting a wallet and clicking Fill Up& will trigger the Proof of Work script.
The final step is to add your SKALE Chain and contract information. Go to the useSKALEFuel React Hook file.
|In production, you may split your configuration and hooks. To simplify the code, the configuration variables have been added to this file.|
Update lines 7-9 as needed:
CONTRACT_ADDRESS should be changed to the value of your deployed contract or the address taken from the hub list
Function_HASH should only be changed if you changed the pay function here
RPC_URL should be changed to match the SKALE Chain you are using.
After updating the values, the dApp should now be conncted to and distribute sFUEL for users on your SKALE Chain.
You now have a fully decentralized and nearly invisible onboarding experience. For a fully invisisble distribution, remove the button and automatically fill up users behind the scenes.