2021年3月18日星期四

One call to contract function generates multiple transactions

I am adding functionality to the Truffle Pet Shop example dApp. I have created a returnPet function in the solidity contract, and have tested it via console and test contracts. I would now like to call it in my JS app.

The problem is, when I call it, the handleReturn() function,

handleReturn: function(event) {      event.preventDefault();        var petId = parseInt($(event.target).data('id'));        var adoptionInstance;        web3.eth.getAccounts(function(error, accounts) {        if (error) {          console.log(error);        }          var account = accounts[0];          App.contracts.Adoption.deployed().then(function(instance) {          adoptionInstance = instance;            return adoptionInstance.returnPet(petId);        }).then(function(result) {          return App.markAdopted();        }).catch(function(err) {          console.log(err.message);        });      });  

generates multiple transactions, and does not affect the blockchain (a different problem. If you have answers to this, I would love to hear them.). As far as I can tell, handleReturn() only gets called once, so why is it generating multiple transactions?

https://stackoverflow.com/questions/66701227/one-call-to-contract-function-generates-multiple-transactions March 19, 2021 at 09:04AM

没有评论:

发表评论