0

The code below is for selling tokens to the smart contract, the INR_ETH.sellTokens() function calls the smart contract. but the code is not working properly, metamask asks for the "approve" part but the selltoken() is never called. nothing shows up in the console log also.

sellTokens: function(){

$('#TS_stage1').hide();
$('#TS_stage2').show();
var XTokens = $('#amount').val();
App.contracts.INR_ETH.deployed().then(function(INR_ETH){
App.contracts.DappToken.deployed().then(function(instance) {
instance.approve(INR_ETH.address, XTokens, { from: App.account }
  ).then(function(){
      return INR_ETH.sellTokens(XTokens,{from : App.account});
    }).then(function(result) {
  console.log("Tokens sold...", result)
   $('#tx_hash').html( result.tx);
    $('#TS_stage2').hide();
   $('#TS_stage3').show(); 
 });
  }) 
})
},

App.account is the current address of the user how called this function dapp.token is the ERC20 token xTokens is the amount to be sold is there some problem in then function

here is the code for buying tokens it has also stopped working the transaction is happening but the console log- "tokens bought" is not called

Tokens: function() {
$('#TS_stage1').hide();
$('#TS_stage2').show();
var numberOfTokens = $('#amount').val();
App.contracts.INR_ETH.deployed().then(function(INR_ETH) {
  return INR_ETH.buyTokens({from: App.account,value: numberOfTokens, gas: 500000}).then(function(result) {
  console.log("hey you");
  $('#tx_hash').html( result.tx);
console.log("Tokens bought...", result.tx);
$('#new_modal').modal('show');
   $('#TS_stage2').hide();
   $('#TS_stage3').show(); 
  })
 })
}

numberoftokens is the ether value the buyer wants to spend

please help, I think there's an error with the function but I am not quite sure. it used to work properly but suddenly stopped working.

as per my analysis, the code is going in the blockchain but is not coming out. it executes everything perfectly until blockchain is called and then it calls blockchain and suddenly comes out of the then function chain, and then nothing is executed neither the js code nor any blockchain calls after that first blockchain call .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.