How to test smart contracts and transactions geth - blockchain

New to solidity and blockchain in general, I tried to make transactions and deploy smart contracts but it seems that we need ethereum to "pay" these actions. Is there any way to get free or "fake" ethereum to easily test transactions and smart contracts ?

Sure, you have basicly two options if you go for the testnet. Don't test stuff on the public main network.
Mine in developer mode
Run geth with the developer flag.
geth --dev --mine --minerthreads 1
From help:
--dev Developer mode: pre-configured private network with several debugging flags
--mine Enable mining
--minerthreads value Number of CPU threads to use for mining (default: 12)
This runs a private testnetwork with your own chain. The miner runs low on one thread to generate new blocks and this way you get testnet Ether in your private network which can be used to pay the fees.
Drain the morden faucet
Join the morden public testnet.
geth --testnet
From help:
--testnet Morden network: pre-configured test network with modified starting nonces (replay protection)
This is the public testnet called morden. It might be too hard to mine but you can just request free testnet ether from the public wei faucet.

In addition to the free testnet Ether method in my other answer, you could also look into development tools and integrated environments for developing smart contracts. Most of them either do not require a real blockchain backend with Ether fees or simulate an Ethereum virtual machine (EVM) and simulate the deployment of smart contracts and decentralized applications.
Among others there are:
Mix (Desktop) and Remix (Web) IDEs for smart contract debugging and development
Solidity Browser (Web) IDE for smart contract debugging
Truffle a development framework for Ethereum
Embark a framework for decentralized apps
Dapple and Dappsys toolchains for fast smart contract development
See also questions tagges with IDE on Ethereum Stack Exchange.

Related

Full nodes for ETH, BTC, and USDT in one server

I want to build a blockchain wallet that works with BTC, ETH, and USDT, I understand that I must to run a server for bitcoin (bitcoin core) and ethereum (Ethereum Node) full nodes.
I have 2 questions now:
1- Has any full node for Tether?
2- Has it any benefit or danger that I will run 3 full nodes in one server?
You don't need to run another node for Tether you just need to connect to ETH an pass it's smart contract data from ethereum blockchain!
which you can see the smart contract here
Try Web3.js and Infura{it has free trial} and use testnet to experiment everything
about security
the only thing that you should keep safe, is the private keys and backup mnemonics

Truffle Suit, real network simulation?

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

Difference of Geth or Ganache

Hi I am new to blockchain topic and I am trying to make an Ethereum smart contract. First step I installed truffle and when I try to migrate it throws an error because I have no ethereum client.
For solving this problem truffle develop, ganache, geth are recommended but I couldnt decide to which one is more suitable and I dont understand the difference of ganache and geth. Basically are they serving same thing or not? Here is error:
Could not connect to your Ethereum client with the following parameters:
- host > 127.0.0.1
- port > 7545
- network_id > *
Please check that your Ethereum client:
- is running
- is accepting RPC connections (i.e., "--rpc" option is used in geth)
- is accessible over the network
- is properly configured in your Truffle configuration file (truffle-config.js)
Truffle
As you already did, you migrated a contract. So Truffle can be used for contract compilation and migration. It aims for easy and fast migration.
Geth
Is an Ethereum-client, which means that you can run your own private blockchain with it. You can adjust your needs by defining for example the amount of threads you offer for mining.
Geth itself is a command line tool, which can run a full Ethereum node implemented in Go. It provides the command lines, a Json-rpc server and an interactive console, where you can run your own scripts written in javascript.
Ganache
If you want a GUI, where you can track all deployments and transactions on your blockchain, you can choose Ganache.
It allows you to create your own private blockchain mainly for testing purposes.
It is used for deployment-testing for example, because there are no real miners on a "ganache-blockchain", so you can test if your contracts work.
I would suggest you to use Geth and Truffle if you want to set up your own blockchain on your local node and then deploy some contracts on it.
There are plenty of manuals online on how to set up your own local node.
For example:
Create your own local node with geth
Setting up Ethereum development environment
After you created your node, you can deploy some contracts with truffle to it. I hope I could help you.
TLDR : start with Ganache and learn Geth along the way.
Truffle is a compiler and out of question.
But between Geth and Ganache :
Why Ganache ? Because it is easy !
Geth is a real deal , for a small local chain you have to run it's service first then create genesis block then you need to bring some miner to mine the transaction to the blockchain and generate some eath! then you can migrate smart contract to it but Ganache will do all of that for you!
Why use Geth? from here :
1- Geth is the official client software provided by the Ethereum
foundation.
2- Comes with a JavaScript console (run it with geth console).
3- Has an interoperable JavaScript client (web3js).
4- Built-in access to the Rinkeby test net (or build your own private
Ethereum network).
5- It is generally considered to be the reference implementation for
other Ethereum nodes.
From my experience at this time/date, Ganache cloud be buggy and will give you some errors irrelevant to your code , but if you need to migrate your code to a test nest like Rinkeby Testnet, eventually you need to learn Geth.

Run solidity/deploy ethereum smart contract on a website

Does anyone know if I can deploy my own smart contract or run/host a solidity code via my own website? I am following this Youtube tutorial by Decypher Media.
If I'm correct, the testrpc address localhost:8545 means that I am deploying the contract as being part of a private blockchain that is only local to my pc, right? This is the case for development. So if I would want to actually deploy the contract as an actual Ethereum node or to the Ethereum blockchain itself, would I just have to replace the localhost:8545 with the actual URL? I am not totally familiar with this yet, but I am really trying to develop something on Ethereum.
I am looking at creating a contract that sends a token to a dynamic number of eth addresses (i.e. today I may have to send tokens to 10 eth addresses, tomorrow I may do it for 15). So, instead of firing the contract for each token which would be time-consuming, I would like to do it automatically/seamlessly. But I want to be able to run my solidity code and handle the contract through my own website instead of running it on the ethereum wallet application or somewhere else.
Anyone, please share some ideas on how we can achieve this, or maybe a summary/outline of the steps that we would need to take to achieve it. Any help would be great! Thanks!
You have many possibilities to achieve this. It depends what you really want to do.
1 - With testrpc :
The easiest way to do this is to run testrpc on a server, for example a free aws-server or azure and expose the testrpc on internet. Then you can replace localhost:8545 by :8545 or using a dns to by-pass the ip.
2 - With a private Ethereum Blockchain :
If you want a real private Ethereum Blockchain, you can build a private node on a aws/azure/google server and expose this node to internet. See this, to learn a bit more : https://blockgeeks.com/two-node-setup-of-a-private-ethereum/
3 - Use a ethereum public network
You can send your smart contract to the public ethereum testnet and then use Metamask and web3js to connect your website to the ethereum testnet. More information for Metamask and how to deploy a contract with Metamask : https://karl.tech/learning-solidity-part-1-deploy-a-contract/ and here https://citywebconsultants.co.uk/blog/blockchain/introducing-ethereum-development-part-1-metamask-and-web3

Accessing Ethereum Dapp

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