1

I am currently learning about smart contracts and there is a question I have.

I am trying to understand how smart contracts are executed. I read already different sources and I tinkered some ideas together but not sure if it is correct.

To deploy a smart contract, I have to send a transaction. A miner takes it, creates a smart contract address and as soon the block is valid, I have to possibility to work with the smart contract.

If I want to execute a smart contract I create a new transaction using the ABI of the smart contract to call a function(s). Since it is a transaction, a miner takes it, executes the code of the smart contract. But what happens now? Is the execution stored in the blockchain with the result of the execution?

I was wondering how this actually works. Let's consider I create a symmetric key encryption smart contract. I send a message and key and the smart contract sends the cipher back. Will the plain text be visible for everyone or just the cipher text?

Thanks in advance

1 Answer 1

2

To deploy a smart contract, I have to send a transaction. A miner takes it, creates a smart contract address and as soon the block is valid, I have to possibility to work with the smart contract.

This is exactly what happens when creating a transaction. You send a transaction with the contract code and initialization parameters. The miners takes the transaction creates a contract address and puts the code in that address and instantiates the contract state by running the initialization part of the contract.

If I want to execute a smart contract I create a new transaction using the ABI of the smart contract to call a function(s). Since it is a transaction, a miner takes it,

Yes, you are correct. When you create a smart contract instance you need to know the ABI and address of the contract. Once you have a instance of the contract, you can send tx to it. This tx is picked up by the miner and executes the tx.

executes the code of the smart contract. But what happens now? Is the execution stored in the blockchain with the result of the execution?

After execution of the code of smart contract, miner updates the state of your contract with the changes you made to the contract by that invocation. The result is not stored, but you can use events to extract them if needed.

Will the plain text be visible for everyone or just the cipher text?

Yes it will be visible to everyone, because your input params are part of the tx which is included in a block so it is public, so the message and key you are sending will be visible to everyone.

1
  • Ok, so it is not a good idea to have an encryption scheme in a smart contract, since everyone can see it. Thank you for you answer :)
    – Donut
    Jun 7, 2017 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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