CryptoFly.us | CRYPTOCURRENCY BITCOIN SHIRTS CLOTHING APPAREL HATS

CRYPTO NEWS

Lock multiple batches of ERC20 tokens for a certain amount of time

I need to build a smart contract where users can lock their ERC20 tokens for a fixed amount of time (same amount of time for all users, e.g. 1 year). Lets say a user locks 100 tokens and half a year later he locks another 100 tokens, the first 100 tokens should still unlock after 6 months and the second batch of tokens after a year.

My current idea is to use an ERC1155 token contract to keep track of the time locks. From the example above, when the first user deposits their tokens, 100 ERC1155 tokens with the token id 0 would be minted that unlock after 1 year. When they deposit the next 100 tokens another 100 ERC1155 tokens with the token id 1 would be minted, and so on. The solution is not ideal because in the worst case scenario a user would have to withdraw multiple times and it would be harder to keep track of all tokens.

Another idea I had that you could have the tokens unlock linearly, so after 3 months 1/4 of the tokens are unlocked, after half a year 1/2 of the tokens are unlocked, etc. When a user deposits more tokens, this equation is adjusted so that the full amount of tokens releases after 1 year but they can still withdraw the same amount as before after depositing more tokens. Would need to figure out the Math behind this one though. This would have the benefit that the total amount of unlocked tokens could be withdrawn at once and it’s easy to keep track of the users balance if tokens are deposited multiple times.

Does anyone have another idea to tackle this issue or maybe is there a project that has similar mechanics already I could have a look at?

error in remix IDE

I am facing this type of Error in ‘remix IDE’ while connecting it to ‘web3.js@0.20.2’ Error: Failed to decode output: Error: insufficient data for uint256 type (arg=””, coderType=”uint256″, value=”0x00″) <!DOCTYPE html> <head> <meta charset=”UTF-8″> <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> <meta http-equiv=”X-UA-Compatible” content=”ie=edge”> <script src=”./node_modules/web3/dist/web3.min.js”> </script> </head> <body> <input id=”name” name=”choice” type=”text”> Vote: </input> <button id=”button”>Submit :::Listen

I am facing this type of Error in ‘remix IDE’ while connecting it to ‘web3.js@0.20.2’

Error: Failed to decode output: Error: insufficient data for uint256 type (arg=””, coderType=”uint256″, value=”0x00″)

<!DOCTYPE html> <head>         <meta charset="UTF-8">         <meta name="viewport" content="width=device-width, initial-scale=1.0">         <meta http-equiv="X-UA-Compatible" content="ie=edge">     <script src="./node_modules/web3/dist/web3.min.js">     </script> </head>  <body> <input id="name" name="choice" type="text"> Vote: </input> <button id="button">Submit : </button> <h2 id="instructor"></h2> </body> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script> <script>      if (typeof web3 !== 'undefined') {         web3 = new Web3(web3.currentProvider);     } else {         // set the provider you want from Web3.providers         web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));     }  // Previous if/else statement removed for brevity  web3.eth.defaultAccount = web3.eth.accounts[0]; console.log(web3.version) var vote= web3.eth.contract([     {         "constant": false,         "inputs": [             {                 "name": "x",                 "type": "uint256"             }         ],         "name": "set",         "outputs": [],         "payable": false,         "stateMutability": "nonpayable",         "type": "function"     },     {         "constant": true,         "inputs": [],         "name": "get",         "outputs": [             {                 "name": "",                 "type": "uint256"             },             {                 "name": "",                 "type": "uint256"             }         ],         "payable": false,         "stateMutability": "view",         "type": "function"     } ]);  vote_add=vote.at('0x6b3c179a96c329dcf93f2d27310c77e88e651af6');  console.log(vote_add); $("#button").click(function() {             vote_add.set($("#name").val());         });  vote_add.get(function(error, result){             if(!error)                 {                     $("#instructor").html(result[0]+' ('+result[1]+' years old)'+result[2]+result[3]+result[4]+result[5]);                     console.log(result);                 }             else                 console.log(error);         }); </script> </html> 

Solidity code:-

pragma solidity ^0.5.0; contract vote {     uint public c0=0;     uint public c1=0;     uint public c2=0;     uint public c3=0;     uint public c4=0;     uint public c5=0;     function set(uint x) public {         if(x==0)         {             c0+=1;         }         else if(x==1)         {             c1+=1;         }         else if(x==2)         {             c2+=1;         }         else if(x==3)         {             c3+=1;         }         else if(x==4)         {             c4+=1;         }         else if(x==5)         {             c5+=1;         }         else         {          }     }     function get() public view returns(uint,uint,uint,uint,uint,uint)     {         return (c0,c1,c2,c3,c4,c5);     } } 

enter image description here

Lock multiple batches of ERC20 tokens for a certain amount of time

Shopping cart
There are no products in the cart!
Continue shopping
0