I need an api to handle erc20 ethereum token deposits and withdrawals on my microjobs website.
Users should be able to withdraw their earned token automatically when they pay the network fees.
I need an api to handle erc20 ethereum token deposits and withdrawals on my microjobs website.
Users should be able to withdraw their earned token automatically when they pay the network fees.
If you are using js, you can use ethers.js or web3.js to interact with the smart contracts when certain functions are needed.
Centralized Solution
For a basic, centralized implementation (assuming an ERC20 smart contract has already been deployed and tokens have been minted / distributed) you and your users would interact with the transfer
function.
On creating a microjob, the creator would use the transfer function to transfer the # of tokens that will be paid for the job to your site (either a general address treasury account or you could create an account per address). Once the use completes the form for this new job, you could request the user sign the transfer transaction. Now the job should exist in the microjobs database and your site will own the ERC20 tokens available.
When it has been determined the job has been completed - some one with access to the treasury account would sign a transaction paying out for the job.
Decentralized Solution A better way to complete this would like be creating a separate contract to manage the creation of MicroJobs and manage the erc20 tokens. In this solution when a job is created, the erc20 tokens would be transferred to this MicroJob smart contract. The creator of the job would then determine when the job is complete and trigger the payment from the MicroJobs contract to the user