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?
live networks - no
emulators - yes
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).
Related
I am learning about NFT minting by using remix to run test code on testnets. Now the function seems to be working as the ETH balance is reduced by the amount of mint price I set, but I can't check the NFTs the given wallet was holding. Is there a way to view it somewhere to check if the NFT is successfully minted?
UPDATE: I see that people can use test nets with their own wallet to receive those NFTs and view them on platforms like Opensea. But is it possible to do the same with VM?
Whether you are using a virtual machine or not, should not have the ability to use Remix or access any testnets. So it is possible. Remix and Ethereum wallets use HTTP to communicate with JSON-RPC nodes that allow your wallets, transactions and other to function.
I am new to smartcontract and start writing some demo code in Solidity to work with Ropsten testing network. I see that I can use send/transfer method in the contract to transfer ether to other accounts. One question about it is that is contract the only way to transfer ether? Can I transfer ether without a contract?
I understand the concept of the contract but not sure whether it is a required thing in Ethereum. When I deploy a contract to the network, it will be sitting in a new block and all transactions generated from this contract are in the same block? Am I understand correctly?
You do not need a smart contract to sign or send a transaction. The transferring of ETH is built into the protocol. This can be accomplished by using libraries such as web3 or ethers if you're a developer. If you're not a developer, this can be accomplished by using tools such as Metamask.
Steps to send a transaction using ethers.js:
Instantiate your provider and signer using ethers.providers. and Signer.
Then sign a transaction using signer.signTransaction.
Use provider to send the transaction using provider.sendTransaction.
References:
Ethers.js: https://docs.ethers.io/v5/api/
web3.js: https://web3js.readthedocs.io/en/v1.5.2/
metamask: https://metamask.io
I'm working on a Dapp for testing Ethereum smart contracts.
I have followed along with this tutorial: https://github.com/Quintor/angular-truffle-box and got the Truffle Dapp working with Ganache-CLI, making me able to do Crypto (I.e. Ethereum) transactions from one to another wallet on this blockchain.
*Note, this is a testing environment so no real Eth are transferred.
The problem I currently encounter is that transactions are direct, and not like the times that are displayed as an option. (Like here, https://ibb.co/ccR8k0J)
The idea is that the more Ethereum (Cryptocurrency) you pay as a fee, the faster the transaction will be done. I wonder if anyone knows how to simulate these times, but on a local blockchain instead of a deployed one.
"ganache doesn't have options to set the consensus mechanism. You could look at puppeth to quickly spin up a geth instance with whatever consensus you want."
By #Stephen S
I'm playing around with an application using Ropsten test network for Ethereum blockchain. I am wondering if there is a way to delete things from there so they do not pollute the blockchain. Or is Ropsten is also immutable as the main one?
No, you can't.
The whole point of a blockchain is its immutability. The Ropsten network primarily differs from the Ethereum mainnet in that Ropsten Ether is worthless (it's for testing only.) Rest is all same as any other Ethereum implementation. As a matter of fact, of all the testnets, the Ropsten network is the closest to the Ethereum mainnet.
EXTRA:
Interestingly, (or not so interestingly), even in your private ethereum chain, the best in terms of 'clearing up the mess' you can do is to remove last N blocks (which hold the transactions). As soon as you pick and remove things, you break the integrity and your chain will become corrupt and void.
Is their a way to access ethereum Dapps other than the mist browser. I was thinking along the lines of a normal browser like chrome. Also, as a sub question how are some Android and IOS apps connecting to the blockchain?
You can do that through Ethereum JSON-RPC: https://github.com/ethereum/wiki/wiki/JSON-RPC
You have to use
eth_call - read from contract
eth_sendTransaction - send transaction to a contract
You must understand that you'll also need to have an Ethereum node started, most probably with unlocked account to execute transactions from it. Which means you don't want to run it on public networks, but rather in local network. That's what Mist do for you essentially.
Also, take a look at MetaMask, it provides same API for browser based app, but requires an additional plugin to be installed into a browser