I am using Ethereum network to deploy smart contract. The contract is written in Solidity and I am using Remix IDE to do the deploy and testing. I am using testing network at the moment.
What I don't understand is that when I deploy a smart contract to Ethereum network, does it create a new block on the blockchain? My contract may send transaction to different account when it is running. Whether this transaction is inside the block of the smart contract? Once I deploy the contract, it should be running inside the network. Whenever there is a method call on the contract, does it always generate a transaction in the block?
There's a slight difference between live networks (e.g. Ethereum mainnet or Ropsten testnet) and emulators (such as Remix VM or Ganache).
When you want to deploy a contract, its compiled bytecode is passed as the data
field of a transaction that doesn't have a recipient (the to
field is omitted).
On a live network, the transaction is broadcasted to the network, and waiting in the mempool to be mined.
When a miner mines this transaction, the EVM on their machine calculates the state changes that were made during its execution (in other words, the contract deployment) and broadcasts the state changes (e.g. storing the contract bytecode under the newly created address storage) to the rest of the network.
However, each instance of an EVM emulator usually runs on one machine (e.g. in your browser in case of Remix) and doesn't have access to a network of miners. Plus it would be ineffective to wait for an external miner to mine your transaction every time during development.
So when you send a transaction on an emulator, it's locally executed and wrapped in a new block right away.
So to answer your questions:
Does deploy a contract mean create a new block in blockchain?
Whenever there is a method call on the contract, does it always generate a transaction in the block?
There's a difference between a transaction (read-write) and a call (read-only). For transactions, see above. Read-only calls are not mined at all (so they are free), and they are only invoked on the machine of your node provider (or in the emulator).