last day (15 days later) » 

11:31 AM
1
A: Avoiding for loop and making function call only once by any user

JaimeThe code below should do. The function giveReferenceId assigns an id to a user based on the address. The array clients save a list of users (just in case you need that list at some point). To be sure that the same address only gets one id, the line: require(referenceid[msg.sender]==0); is used...

 
Sorry it is not working with same id i am able to create 2 refrence ids remix.ethereum.org/…
 
you mean with the same address you can register two different Ids?, this is no possible. Also, I run this in remix, if you try to execute giveReferenceId twice with the same address the transactions revert
 
No i want the user must call Give refrence id function() only once he shouldn't be able to call it twice
 
You seem to be confused. You can not prevent the user from calling the function, what you can do is to reject the call by reverting if the subject already has called it, such that he/she doesn't create two different ids with the same address, and this is exactly what the contract does.
 
Thanks john i want same functionality what you can do is to reject the call by reverting if the subject already has called it, such that he/she doesn't create two different ids with the same address, and this is exactly what the contract does But just see the transcations on etherscan with same address i called 3 times the function and generated 2 ids
 
11:31 AM
give me the address where you deployed the contract
 
0x0dd87fe70e4ed0af92f656396e9b7949aeb33cfc
 
Hey, the contract that you deployed is not the contract that I posted in my answer, what contract is this?
 
Sorry i worked with the previous transcation instance
 
No problem, those things happen, if this solved your question please accept the answer.
 
can you plese explain these line of code require(referenceid[msg.sender]==0); and how to read the data from logs without writting second function
 
11:31 AM
referenceid is a mapping, by default the values are set to zero (0). In this case if I mapp the user address the value returned is zero if the address has not been registered, so the require ask if the mapping avlue is zero and if not, it cancell the execution without assigning a new id. What do you mean by "how to read the data from logs without writting second function?", what data? there is a second function getrefrnceId() that returns the id of the user that calls it. is that what you mean?
 
Sorry james for length discussion Can we see the id without writting getrefrnceId() function
 
what do you mean? executing this won't cost you any gas because the function is 'view'
 
yes but i don't want some one to go to second function to see the id first function should give the id i tryed i got logs [] i tried to slice the log as we do in test but i failed
 
11:46 AM
The first function returns the id, as the id and the idcounter are the same. There are not events in the contract that is why you get logs[]
look at the answer again, I edited it to include an event, then you will get the user address and the id in the logs.
hope this works for you
 
12:01 PM
THanks jaime nice to chat with you and Thanks for your help
 
12:19 PM
[block:3257312 txIndex:4]from:0xc2a...32fa8to:GiveRefreceId.giveRefrenceId() 0x6d5...b09c5value:0 weidata:0x013...efc41logs:1hash:0x1bf...05c2b
these is what i am seeing from return of giveRefrenceId () function i am not able to see the id
 

last day (15 days later) »