In this example we used the Dapp Builder to compile a front end example and an administration example.
This is a real world example and use case for accepting tFuel to gain access to a subscription service such as a video delivery platform. We will be using an account number and timestamp for access and validating payment to the platform. The subscription service could then use the tFuel received to pay for use of the Theta Video API.
A user would have an account number then make a payment for 30 days, 6 months, or 1 year. The contract will check if they have a active subscription, based on the account's timestamp in the contract. For example if they have 5 days left and buy 30 days then they will have 35 days to use the platform. If they are new or their subscription has ran out it will add the time from the current block time.
The function "memberPayment" is called to pay for the membership. When using this funtion the account number and term lenght must be specified. (1 for 30 days, 2 for 6 months, and 3 for a year.) We used one function instead of a function for each payment type. It will check to ensure the exact amount is being sent, if more or less tFuel was sent it will revert the transaction.
After you have deployed the contract above enter the contract address below then click Download Front End and Download Admin Dapp to save the HTML files. Then upload them to a web server and test interacting with your contract using a Dapp.
In a real world use case the account number would be provided after they login and a user would not have to enter it. For this example you will need to enter one when using the front end (Example: 123).
Note: If you make changes to the contract the Dapp may not work correctly. It may need to be rebuilt using the Dapp Builder and your new contract.
*Thetascan.io will never ask for your private key. All interactions with the blockchain in the Smart Contract HQ use the MetaMask Wallet to interact with the blockchain.
© 2024 Thetascan.io