0

I've got two related questions:

1- Can I develop a contract that will be triggered when the transaction is sent to another contract (that is not owned by me)?

For example, every time that a Tx for cryptokitties is inserted into the blockchain, add 1 to a counter in my contract.

2- Is it possible that a smart contract will scan and retrieve the first Tx that submitted to a contract? (and after that the second and so on..) -I know it is possible to do it "off-line". But I want to enforce it on a contract.

Thanks.

0

1) To "trigger" contract you must call function from other contract or SDKs, you can't subscribe events like in other programming languages.So to achieve goals you described, you would need some app to listen to cryptokitties events and then call function from the contract when such events are received.
Contract is run only when you call it, so when it has done everything what you programmed in function, it's back to "idle" state until you call function next time.

2) Not sure if i understood your question right, but if you want to do something on contract when other contract is called, you can't (since events can just be called, but not listened to). So if the other contract does not call your contract, there's no way to know when the tx was submited in other contract.

0

1- Can I develop a contract that will be triggered when the transaction is sent to another contract (that is not owned by me)?

No, this cannot be done currently purely with contract. There is no way for contracts to access the logs. Also, somebody has to pay for the gas your event listener would use. As it stands, that can only be the initiator of a transaction. You can imagine things could become quite expensive for users this way.

2- Is it possible that a smart contract will scan and retrieve the first Tx that submitted to a contract? (and after that the second and so on..) -I know it is possible to do it "off-line". But I want to enforce it on a contract.

Not possible either. Smart contracts in Ethereum only have access to the current state, as well as some metadata of the past 256 blocks.

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.