1

Am not sure if the question was already asked somewhere, I tried searching but couldn't get it.

This is what I have done so far.

  1. Created and deployed Token Contract
  2. Created and deployed CrowdSale Contract

Now, how do I list out the transactions sent by an address (person) to the crowdsale Contract to buy the token. I checked the codes to know the number of tokens bought by the address, but I also want to show the number of ethers he sent at various phases of the crowdsale. I know there is API endpoint to pull out the transactions of an address, but here I want to get the transaction done only with the CrowdSale Contract.

Hope I was able to explain the need. Any help is appreciated.

2

Personally my apporach is to use events inside contract which is pretty easy to list Transaction detail with specific information e.g

In contract i define event like this

event buy(address indexed customerAddress, uint priceValue, uint amount);

Then in js file like this

var buyEevent= contractInstance.buy({customerAddress:customerAddress},{fromBlock: 0, toBlock: 'latest'});
            buyEvent.watch(function(error, response) {
                 if (!error) {
                      console.log("event: "+response.args.customerName);
                      console.log("event: "+response.args.priceValue);
                      console.log("event: "+response.args.amount);

                 } else {
                      console.error(error);
                 }
            });

Hope it may be helpfull for you.

  • Thanks. Guess purchaseEvent.watch should be changed to buyEevent.watch – Rajesh Oct 26 '17 at 10:31
  • thanks for correction @Rajesh , i make changes to my solution so, i forget to change name there – Afzaal Ahmad Oct 26 '17 at 10:48

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.