Ganache-Cli and Metamask generates completely different accounts from the same mnemonic - ethereum

When I run
ganache-cli -m impose royal miracle dismiss scale quiz sausage bus odor liar rent scheme country lend vivid demand autumn purpose clog skill symptom ketchup fringe hen
I get these accounts in the terminal
(0) 0x22c0D02Df846Df59955c991C0359acD414387Bb0 (100 ETH)
(1) 0x433Ff1a6D635E9F294916c8A83629A18539391CF (100 ETH)
Whereas if I use Metamask I get
(0) 0x588fcACd850599385705789156F0066c470bf9Da
(1) 0xDCd05B8eD4158F27BFd515C7e001a35EB40e8B2e
Why is there a discrepancy? Shouldn't they give the same address?

Are you trying to import Ganache accounts into your Metamask?.

Related

Why is constant node participation necessary in blockchains?

From Avalanche's whitepaper in the context of Nakamoto consensus protocols:
By construction, they cannot quiesce: their security relies
on constant participation by miners, even when there are no
decisions to be made.
I understand why blockchain's require active participation from nodes when transactions are being registered (to ensure that the transaction is not malicious), but what is the concern when the system is dormant and no transactions are being created?
If all transactions stopped and all nodes went inactive for a day, what would be the risk during that time / when the system becomes active again? Why can't they quiesce when no decisions are to be made?
If all transactions stopped and all nodes went inactive for a day, what would be the risk during that time / when the system becomes active again? Why can't they quiesce when no decisions are to be made?
There is no risk within the system. However if a blockchain halt for a day then a lot of interconnected world goes boom. You can study this when Solana halted several times over the last few years.
No payments work
People cannot move funds in and out in centralised ramps
On-chain decentralised finance markets go out of sync with other markets
Price feeds go out of sync
Collateral liquidations for lending markets may not happen timely; lending protocols go net negative
Generally, one the value promise of decentralised network is 100% uptime due to resiliency from decentralisation. If the network cannot be guaranteed to be 100% functional, this value promise disappears and greatly causes users to doubt the benefits of decentralisation.

Solidity: deploy contract, mint 50 nfts, and send nft to 50 hard coded addresses all in one step possible?

Is it possible and or advisable to, in one step, deploy a smart contract, have it mint 50 nfts and send those 50 nfts to 50 different addresses all in one transaction?
Or would it be better practice to split these 3 different actions into two different transactions?
Would love any references to existing smart contracts that do anything similar!
Thank you!
It is not advisable to run Solidity functions with long running for loops that may exhaust the available gas. Because you are minting 50 NFTs it is likely you cannot fit all the execution function to a single Ethereum transaction and you need to do minting in smaller batches.

Can I avoid gas fees by running my own Ethereum node?

Gas costs for even a simple contract deployment are astronomical. If I spin up my own node and connect directly to it can I deploy on that node and avoid the gas fees?
Can I avoid gas fees by running my own Ethereum node?
Simple answer: No.
A node accepts the transaction, stores it in its mempool, and relays it to other nodes so that they can also store it in their mempool. There's nothing related to gas costs at this point.
Theoretically you could deploy a contract for "free" by running your own miner. But that's impossible without professional hardware costing very large amounts - many times more expensive than what you'd save on the gas fees.
However, in a block that you mined, you could include a transaction deploying a contract with 0 gas price. This sometimes happens - miners do occasionally put their own 0-priced transactions in their own blocks. But apart from that, no miner would accept your transaction with 0 gas price (or any transaction priced lower than the current market rate), as that wouldn't be profitable for them.

Do I need to pay gas fees to distribute my ethereum based crypto?

If I were to create my own Ethereum based crypto token named "ExampleCoin" with a supply of 1,000,000,000 and decided to distribute it to users for playing my game, would I need to pay a gas fee each time I give a user some ExampleCoin?
And if I had an in game store where users can make purchases with ExampleCoin, would a gas fee need to be paid in order to send ExampleCoin from the user to the game?
Gas is like gasoline to the Ethereum network; whenever we interact with the blockchain and affect its state, we must pay the fee required to perform the computations and process the transaction [1]. Each action such as storing values, sending tokens, adding integers etc. has associated cost in gas units [2]. The total gas cost for a transaction is multiplied by a gas price [3] to get the gas, or transaction, fee.
The transaction in which the ExampleCoin contract allocates some ExampleCoin tokens to a user, will be initiated by the user who will have to pay the required gas fee. Thus, it is the user who will initiate the transaction which will allocate the tokens to him, and thus he will pay the gas fee.
Similarly, when the user makes purchases with ExampleCoin, he is making a transaction affecting the state of the blockchain and thus incurring gas cost; so, he will have to pay the gas fee.
The bottom line is that whoever makes a transaction will have to pay the required gas fee. In this case, it would be the user, and not your contract, who pays the gas fee.
It is because of the increasing gas prices and thus transaction fees on the Ethereum network that solutions like sidechains, and other blockchains focusing on low transaction fees such as Solana have been developed. Thus, as a smart contract/ dapp developer, one has to comprehensively ascertain the business logic of one's application and decide which network to deploy it on, keeping the end user's experience in mind.
[1] See these explainers on gas and transactions:
https://ethereum.org/en/developers/docs/gas/ https://ethereum.org/en/developers/docs/transactions/
[2] See page 27 of the Yellow Paper for a list of operations and associated gas cost in gas units. For example, the base gas cost for every transaction is 21000 gas units: https://ethereum.github.io/yellowpaper/paper.pdf
[3] This is the amount in ETH we are willing to pay to the miner, per gas unit, as incentive to include our transaction in the next block. The higher the gas price, the more quickly our transaction is picked up by miners and mined.
If this is your private network and you do not want to use the gas mechanism to pay for transactions, then use Quorum - it does not require a transaction fee, and smart contracts are similar to Ethereum.
If you want to use Ethereum in your network, then you will have to come up with a mechanism for automatic distribution and compensation of Eth on user accounts. The simplest option is to give 100,000 Eth to the user's account when registering.

Some total newbie questions on NFT and Ethereum

I'm interested in the conceptual topic of creating rights managements systems on the the Ethereum block chain with digital assets represented by an NFT.
I am just reading up on how to write programs that run on Etherium but I have some very basic questions just to get to started.
I read that NFT are created on the Ethereum blockchain. I don't really understand if that is the same block chain on which the currency Ether is maintained? Seems like the ledger will become impossibly large huge if both the every currency transaction and every digital asset and copy thereof that migrates to Ethereum is stored in one single giant ledger and that each miner on the chain has to download the entire ledger to one single machine in order to validate transactions? Have I got big misunderstanding there? I know there is talk about "sharding" in the future, but it seems like that isn't coming very soon.
Cost of running a smart contract on the blockchain? Assuming that the we are talking about the same block chain, from what I can see the price of "Gas" is quite high. I'm reading that the price of ETH transfer from one party to another is 21,000 Gwei, about $0.03 today. Just trying to understand the basics, how much does it cost to create a NFT? And roughly how much does it cosst to execute a simple function on the blockchain (without loops). Let say the equivalent of 5 statement function which takes a few simple params, reads a few blocks, doesn't write to the block chain but just performs some simple math and a few if statements and returns a string? Does that also cost, like, more than penny? Is the conversion to ETH2 switch from proof of work to proof of stake going to bring those costs down by orders of magnitude?
Any good resources or reference on how to write programs which create and manipulate NFTS on Etherium? Most of what I have seen in the bookstores seem to cover financial transactions with Ether.
Yes, it's the same blockchain.
You can see in the stats that full node (stores current state) currently takes about 400 GB and archive node (stores current and historical states as well) takes about 6.6 TB.
My observation is that most web apps using blockchain data don't verify and trust a third-party service running a node (such as Infura). And I believe that most end users or businesses who want/need to verify, usually have the capacity to store 400+ GB and are able to scale.
But if this amount of data is okay or "impossibly large huge", I'll leave that to your decision. :)
Deployment of a token smart contract usually costs between 500k to 3M gas. My estimate is that most token contracts with basic features that were compiled with an optimizer, cost around 1M gas to deploy. With current prices of ~200 Gwei/gas and $1800/ETH, that's about $350. But I remember just few months ago the average gas prices were ~20 and ETH cost $500, so that would be around $10. So yea, the cost of deploying a contract is very volatile.
Simple function that performs validations and transformations in memory is going to cost the base 21k + few hundred gas. (Working with memory data is cheap gas-wise, accessing the storage is much more expensive.) So in current prices around $7, few months ago it could have been $0.25.
As for the question, whether ETH2.0 is going to bring lower gas price: My opinion is that L2 (which should be released earlier than PoS) is going to have some effect on the price since it allows for sidechain transactions (similar to Lightning network on Bitcoin). But this is a development forum, so I'm not not going to dive deeper into price speculations.
I recommend OpenZeppelin docs where they cover their opensource implementations of ERC standards (including ERC-721 NFTs) or googling the topic you're interested in and read articles that catch your eye (at least that's my current approach).
And if you're new to Solidity in general, I recommend at least few chapters from CryptoZombies tutorial. In my opinion, the first few chapters are great and you'll learn a lot, but then the quality slowly fades.