Truffle installation issue “-bash : truffle: command not found”

i'm trying to set up the environment for developing dapps on my mac using&nbsp;<a href="https://medium.com/tomochain/how-to-build-a-dapp-on-tomochain-85532a1192e7" target="_blank">https://medium.com/tomochain/how-to-build-a-dapp-on-tomochain-85532a1192e7</a>&nbsp;tutorial. upon installing truffle, i am unable to use truffle commands from project directories. i think there is some issue with setting up the path variable or truffle not being a global installation. Here is the output from the console

i'm trying to set up the environment for developing dapps on my mac using https://medium.com/tomochain/how-to-build-a-dapp-on-tomochain-85532a1192e7 tutorial. upon installing truffle, i am unable to use truffle commands from project directories. i think there is some issue with setting up the path variable or truffle not being a global installation. Here is the output from the console

Sheikhs-MacBook-Air:~ Zubair$ node -v v10.15.1

Sheikhs-MacBook-Air:~ Zubair$ npm -v 6.4.1

Sheikhs-MacBook-Air:~ Zubair$ truffle version -bash: truffle: command not found

Sheikhs-MacBook-Air:~ Zubair$ ./node_modules/.bin/truffle version Truffle v5.0.3 (core: 5.0.3) Solidity v0.5.0 (solc-js) Node v10.15.1

Sheikhs-MacBook-Air:~ Zubair$ cd pet-shop-tutorial

Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ truffle version -bash: truffle: command not found

Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ ./node_modules/.bin/truffle version -bash: ./node_modules/.bin/truffle: No such file or directory

Sheikhs-MacBook-Air:pet-shop-tutorial Zubair$ npm config get prefix /Users/Zubair/pet-shop-tutorial/~.npm-global

Top 10 Best Blockchain Programming Language for Blockchain Programmer

Top 10 Best Blockchain Programming Language for Blockchain Programmer

We aim at equipping you with every necessary knowledge of the best programming languages for blockchain and you'll learn more 10 Best Blockchain Programming Language for Programmer: C++, Java, Python, Ruby, Solidity, Go, JavaScript...

We aim at equipping you with every necessary knowledge of the best programming languages for blockchain and you'll learn more 10 Best Blockchain Programming Language for Programmer: C++, Java, Python, Ruby, Solidity, Go, JavaScript...

If you’re a tech-oriented person like me, chances are you’ve wondered at least once about all those latest fusses regarding blockchain and cryptocurrencies. So, what is this blockchain and why’d you be tempted to learn more about it? Blockchain, as the name suggests, is a chain of blocks; connected sequentially using complex cryptographic logic.

This technology was implemented first by Satoshi Nakamoto and was first used in the implementation of the popular BitCoin cryptocurrency. The blockchain technology is being used heavily in the industry, thanks to the high-level of security it provides in business transactions. From corporate firms to industrial banks, blockchain developers are sought everywhere equally. So, wielding this modern-day skill by learning the best blockchain programming language guarantee you an edge over your fellow developers.

Which are the best programming languages for blockchain? Developers are presently utilizing prevalent programming languages like C++ and Java to manufacture custom blockchain programs. What’s more, digital money specialists have made languages like Simplicity and Solidity that are explicitly intended for blockchain improvement.

The worldwide Blockchain market is right now worth an expected $1.2 billion and specialists foresee that it will arrive at a $57 billion valuation by 2025, developing at over 69% every year.

Significant enterprises and investors are teaming up with Blockchain counseling organizations to grow new digital currency innovation, savvy contracts, conveyed records for customary banks, gaming tokens, and inventory network the executives frameworks.

What Is Blockchain?

Customary financial uses a bank as the record and mediator. To move cash to a companion, an individual should initially contact their own bank and request that they move cash to a particular record number. The bank checks the sender’s record for assets, moves those assets to the goal, and records the exchange on the sender’s record. The accepting bank must accomplish something very similar.

In any case, the issue with this customary financial framework is that records are put away inside and are defenseless against hacking and control.

Blockchain disposes of this hazard by putting away all records online in a decentralized, unknown record that can be gotten to by anybody. Blockchain uses squares, or accumulations of information, like spreadsheet lines and segments, to store information. Squares are added to the “chain” in successive request.

In contrast to conventional bank records, which are put away inside, each blockchain client has a total record of the whole blockchain on their PC. This implies they can rapidly discover any exchange that has ever happened in the event that they have the comparing hash code. Since that information is put away freely, it can never be changed or erased — giving clients genuine feelings of serenity and trust in the framework.

Organizations keen on exploiting the blockchain upset should scan for up-and-comers with skill in the accompanying programming languages.

Here are the best programming languages for Blockchain

1. C++

C++ keeps on being one of the most famous programming languages in the tech world and is a prevailing power in the blockchain business also. The article arranged language is ideal for blockchain improvement, since it utilizes similar standards, for example, epitome, deliberation, polymorphism, and information covering up, as blockchain to avoid incidental alters to information.

Engineers additionally prize C++ in view of its memory control abilities. The language helps keep squares secure and deal with an enormous number of asset demands by enabling each system hub to acknowledge or dismiss individual squares.

C++ is additionally utilized broadly by blockchain advancement administrations due to the manner in which it handles parallel undertakings and stringing. The language is equipped for taking care of both parallel and non-parallel assignments, notwithstanding improving single-string execution.

EOS is an awesome case of a blockchain program worked with C++. The open source programming was discharged by Square in 2018 and is intended to process exchanges more rapidly than choices by restricting the product to only 21 square creating hubs. This enables the product to affirm an exchange in under a second and settle it in only two minutes.

2. JavaScript

GitHub as of late positioned JavaScript as the most mainstream language for developers — with a fantastic 95% of sites utilizing it here and there. Be that as it may, JavaScript isn’t just the lord of web advancement; the adaptable programming language is additionally utilized broadly for blockchain improvement.

One reason why blockchain designers prize JavaScript is a direct result of the manner in which it handles offbeat code. This is significant in blockchain, as thousands or even a great many exchanges might be started simultaneously. Offbeat, parallel programming empowers a program to finish numerous activities all the while. Standard, synchronous programming just can’t deal with that volume.

By running numerous activities on the double, offbeat code can improve programming responsiveness and application execution. This empowers blockchain projects to deal with the enormous volume of activities without hindering execution and disappointing clients.

You may also like: How to Build a Blockchain in JavaScript.

3. Java

The only language that can challenge the reign of C++ in the industry is Java, and for good reasons so. Java is in many ways similar to C++ regarding its object-oriented approach and a vast community of third-party applications and platforms. The main reason to use Java as the de-facto blockchain programming language in the industry is, however, its highly-capable portability.

Programs written in Java are portable across any computational device, as they don’t rely on system-specific architecture, instead uses the universal JVM(Java Virtual Machine) for execution. This makes Java one of the best programming languages for blockchain.

4. Python

Python is probably THE most trending programming language you can learn these days!

It's very popular because it's easy to learn and use, runs on all operating systems and allows you to build a broad variety of programs: Be that web applications, desktop applications, utility scripts or using it for data science and machine learning.

You'll do so whilst building your own Blockchain and Cryptocurrency. These are of course also highly trending topics and not a lot of people understand what a Blockchain really is, you'll learn a lot about the core concepts of the Blockchain and you'll see how Python can be used for the many aspects that make up a Blockchain and Cryptocurrency.

You may also like: Building a Blockchain with Python.

5. Solidity

Solidity is a savvy contract and blockchain improvement language that is utilized broadly by Ethereum designers. The area explicit language utilizes a significant number of indistinguishable standards and punctuation from JavaScript to make high-caliber, decentralized applications.

Engineers lean toward the language since it enables them to compose elevated level code for the Ethereum blockchain arrange, the second-most famous blockchain digital currency, which can be assembled into low-level machine code. It additionally enables people to use the Ethereum advanced exchange record to make brilliant agreements between organizations.

The agreement situated language utilizes invariants, preconditions, and post-conditions to streamline the advancement procedure and to make the agreement age process easier for clients.

Solidity is at present accessible on a scope of blockchain stages, including Ethereum, Ethereum Great, Tendermint, and Counterparty. It’s utilized for a scope of utilizations, including business contracts, barters, crowdfunding, and that’s just the beginning.

6. Ruby

Although quite old and tested by the industry, Ruby gained momentum as a blockchain programming language in the last couple of years or so. Ruby, an interpreted high-level language with object-oriented features, much like Python, can be a viable blockchain coding language for uncountable reasons. It offers developers the ability to prototype their vision rapidly using open source third-party APIs and plugins.

The Ruby ecosystem is thriving with loyal contributors since its inception as the de-facto web language starting from the first half of this millennium. It’s especially prevalent within the Asian developers, the most substantial fraction of open source blockchain developers.

7. Simplicity

Simplicity is a fresh out of the plastic new programming language that was discharged in November 2017 and planned explicitly for shrewd agreements and blockchain improvement. The language conceals low-level consistent parts from architects so as to expand efficiency and stay away from engineer interruptions, which is one motivation behind why it is quickly winding up well known in the network.

Like C++, Effortlessness is an item arranged language that uses indistinguishable standards from blockchain to forestall blunders and changes to information. It additionally utilizes Merklized Theoretical Sentence structure Trees to sort out the projects into trees — along these lines taking into account littler exchange sizes and lessening square space prerequisites.

The language’s makers, Blockstream, are as yet extending the language and its abilities. Designers can hope to see Simplicity being utilized in more applications towards mid-2020 once the language is incorporated into Bitcoin and its highlights are concluded.

8. Go

The brainchild of Robert Griesemer, Rob Pike, and Ken Thompson, pioneer of modern programming languages, Go is the best blockchain programming language for building hyper ledger fabric. The statically-typed yet compiled language is on par the performance level needed by a blockchain coding language. Go comes with every advanced feature you’d need when building your first blockchain, namely classes and inheritance, generics, annotations, constructors, and exceptions.

Go offers top-notch concurrency support in blockchain applications, thanks to its smart implementation of channels and interfaces. So, it’s one of the best programming languages for blockchain when it comes to developing a system that is not only efficient but also lightning fast.

9. Rust

The newest blockchain programming language on the block currently, Rust aims at providing open source devs the capability to build fast and efficient blockchain systems. We found Rust to be exceptionally good when it comes to CPU-bound tasks. You can take either a functional approach or an imperative one with Rust for developing your blockchain.

It’s one of the best programming languages for blockchain due to its highly-capable mechanism of handling mutable states. The Rust compiler provides awe-inspiring optimization of your blockchain. The fast, memory safe, and exclusively concurrent nature of this blockchain coding language makes it most suitable for developing real-world blockchains.

10. PHP

Although dimmed not suitable for modern web anymore, PHP still covers the majority of web systems. It can be utilized to build simple to complex blockchain systems as well, thanks to its object-oriented features and a vast active open source community.

If you’re a new programmer looking for getting your hands dirty at blockchain coding, PHP might turn out to be the best option for you. A considerable number of PHP developers will guarantee a ready workforce in case you develop something highly capable and intend on going corporate.

Summary

Blockchain is here to stay. The popular record-keeping technology is what makes cryptocurrency exchanges possible and is widely used by corporations, individuals, and blockchain consulting services for software development.

Developers can easily use popular programming languages like C++ and Java for blockchain development. Alternatively, the community has recently created blockchain-specific languages like Solidity and Simplicity which make cryptocurrency development a smooth process.

Expect to see more original languages spring up over the next several years, as the blockchain market continues to grow rapidly and cryptocurrency begins to be used by ever-larger numbers of people.

Thank for reading!

Learning Solidity

Solidity is a high-level language used to implement smart contracts. This is an object oriented language designed to target the Ethereum Virtual Machine. Let's explore it!

Introduction

Solidity is a high-level language used to implement smart contracts. This is an object oriented language designed to target the Ethereum Virtual Machine. Let's explore it!

Let's go!!!

Let's create a file called Contract.sol

First, you must define the version you are using. This is an information the compiler needs.

pragma solidity ^0.4.22;

All code in Ethereum belongs to a Contract. Let's create a contract and define a few variables inside it.

pragma solidity ^0.4.22;

contract DeveloperFactory {
// Let's create a Developer!
uint dnaDigits = 16;
uint ageDigits = 2;
}

Solidity is a typed language. uint stand for Unsigned Integer ( non negative integers ). These variables are state variables. They will be permanently stored in the contract storage ( in the Ethereum Blockchain ). Our Developer has a dna of 16 digits and an age of 2 digits.

Let's keep going!

Struct and arrays

pragma solidity ^0.4.22;

contract DeveloperFactory {
// Let's create a Developer!
uint dnaDigits = 16;
uint ageDigits = 2;

struct Developer {
    string name;
    uint dna;
    uint age;
}

The struct variable allows us to define more complex data structures. Here the Developer struc takes a string called name, a uint called dna and a uint called age.

Solidity also has arrays. You can create dynamic or fixed arrays. Here, our Developer array is dynamic because we do not specify a length. So we can keep adding Developers to our army without any limitations.

Developer[5] public developers is a fixed array that can contain 5 Developer struct.

Functions

A function would look something like this:

pragma solidity ^0.4.22;

contract DeveloperFactory {
// Let's create a Developer!
uint maxAge = 100;
uint minAge = 5;

struct Developer {
    string name;
    uint id;
    uint age;
}

Developer[] public developers;

function _createDeveloper( string _name, uint _id, uint _age ) private{
    developers.push( Developer( _name, _id, _age ) );
}

function _generateRandomId( string _str ) private pure returns (uint){
    uint rand = uint(keccak256(_str));
    return rand;
}

function createRandomDeveloper( string _name, uint _age ) public view {
    require(_age &gt; minAge);
    require(_age &lt; maxAge);
    uint randId = _generateRandomId( _name );
    _createDeveloper(_name, randId, _age );
}

}

We create functions with the function keyword. Functions can take parameters. By default, functions are public. I added the private keyword to make this function private. I also chose to add an underscore before a private function or variable to distinguish them from public variables. You don't have to do this, I just find it easier to read.

Ethereum has the hash function keccak256 built in. This is a version of SHA3. Pass it any string and you get a 256-bit hexadecimal number.

As you can see, we are typecasting the keccak256 value into a uint value and we return it.

Aside from the private keyword, there are several things you can add to a function:

  • The function returns something: Use the returns keyword and specify the type the function returns. Here, it will return a uint type.
  • The view keyword means that our function needs to look at some of our contract's variables, but not modify them. Our function createRandomDeveloper needs to look at minAge and maxAge variables.
  • The pure keyword means that the function is not accessing any data in the app. It only returns something depending on its parameters. Our _generateRandomId is pure.

We have three functions. _generateRandomId generates a random Id for our developer by using the keccak256 built in function. _createDeveloper creates and pushes a new Developer struct into our developers array. createRandomDeveloper is the only public function. It checks if the age provided is correct. The require statements will throw errors if it is not the case ( age greater than 100 and lower than 5 in our case ). So, this last function is the one that can be called from outside our contract.

Events

You can also create events so you can communicate what happens on the blockchain to your front-end app. Your app would then listen to those events and react accordingly.

pragma solidity ^0.4.22;

contract DeveloperFactory {
// Let's create a Developer!

event NewDeveloper(uint devId, string name, uint age);

uint maxAge = 100;
uint minAge = 5;

struct Developer {
    string name;
    uint id;
    uint age;
}

Developer[] public developers;

function _createDeveloper( string _name, uint _id, uint _age ) private{
    uint id = developers.push( Developer( _name, _id, _age ) ) - 1;
    newDeveloper(id, _name, _age);
}

function _generateRandomId( string _str ) private pure returns (uint){
    uint rand = uint(keccak256(_str));
    return rand;
}

function createRandomDeveloper( string _name, uint _age ) public view {
    require(_age &gt; minAge);
    require(_age &lt; maxAge);
    uint randId = _generateRandomId( _name );
    _createDeveloper(_name, randId, _age );
}

}

Mappings

After struct and arrays, we can also store data in mappings. Mappings are a key-value store. For example:

mapping(uint => string) public keyUintStringValue;
mapping(address => uint) public addressToUint;

Here, we have two public mappings. The first one has a uint key and a stringvalue. The second has an address key and a uint value.

Addresses

The Ethereum blockchain is made up of addresses. Each account has an unique address. It takes the following form: 0x0cE440255306E921F41612C46F1v6df9Cc969183. Each address has a certain amount of Ether, which is the cryptocurrency used on the blockchain, and can receive or send Ether to other addresses.

With that in mind, let's create a new mapping for our DeveloperFactory:

pragma solidity ^0.4.22;

contract DeveloperFactory {

event NewDeveloper(uint devId, string name, uint age);

uint maxAge = 100;
uint minAge = 5;

struct Developer {
    string name;
    uint id;
    uint age;
}

Developer[] public developers;

mapping (address =&gt; uint) public ownerDevCount;
mapping (uint =&gt; address) public devToOwner;

function _createDeveloper( string _name, uint _id, uint _age ) private{
    uint id = developers.push( Developer( _name, _id, _age ) ) - 1;
    NewDeveloper(id, _name, _age);
}

function _generateRandomId( string _str ) private pure returns (uint){
    uint rand = uint(keccak256(_str));
    return rand;
}

function createRandomDeveloper( string _name, uint _age ) public view {
    require(_age &gt; minAge);
    require(_age &lt; maxAge);
    uint randId = _generateRandomId( _name );
    _createDeveloper(_name, randId, _age );
}

}

In the first mapping, we will keep track of the number of devs each account ( address ) created. In the second, we will keep track of the owners for each dev.

msg.sender

Each contract is passive, they don't do anything until someone triggers them. msg.sender is a global variable that allows us to know which address is responsible for the triggering. It could be a account or another smart contract.

With that information, we can update our mappings appropriately. In the _createDeveloper function, we will increase the ownerDevCount for this particular address. In the devToOwner mapping, we will indicate that the newly created developer is owned by the msg.sender address.

pragma solidity ^0.4.22;

contract DeveloperFactory {

event NewDeveloper(uint devId, string name, uint age);

uint maxAge = 100;
uint minAge = 5;

struct Developer {
    string name;
    uint id;
    uint age;
}

Developer[] public developers;

mapping (address =&gt; uint) public ownerDevCount;
mapping (uint =&gt; address) public devToOwner;

function _createDeveloper( string _name, uint _id, uint _age ) private{
    uint id = developers.push( Developer( _name, _id, _age ) ) - 1;
    ownerDevCount[msg.sender]++;
    devToOwner[id] = msg.sender;
    NewDeveloper(id, _name, _age);
}

function _generateRandomId( string _str ) private pure returns (uint){
    uint rand = uint(keccak256(_str));
    return rand;
}

function createRandomDeveloper( string _name, uint _age ) public view {
    require(_age &gt; minAge);
    require(_age &lt; maxAge);
    uint randId = _generateRandomId( _name );
    _createDeveloper(_name, randId, _age );
}

}

Notice the ++ notation to increase the ownerDevCount[msg.sender], just live Javascript!

Inheritance and import

Contracts can inherit from other contracts. If you open a new file call DeveloperLearning.sol, you can make it inherit from DeveloperFactory.sol:

pragma solidity ^0.4.22;

import "./DeveloperFactory.sol";

contract DeveloperLearning is DeveloperFactory {
// I have now access to DeveloperFactory functions
}

Notice how we imported the DeveloperFactory contract ( assuming it was in the same folder ). To declare inheritance, we use the keyword is.

payable

In order for a contract to receive ether, we need to have the payable keyword to a function. The amount sent will be accessible in the global variable msg.value. So we could make sure that a certain amount of ether is sent to the contract before the creation of a developer:

pragma solidity ^0.4.22;

contract DeveloperFactory {

event NewDeveloper(uint devId, string name, uint age);

uint maxAge = 100;
uint minAge = 5;

struct Developer {
    string name;
    uint id;
    uint age;
}

Developer[] public developers;

mapping (address =&gt; uint) public ownerDevCount;
mapping (uint =&gt; address) public devToOwner;

function _createDeveloper( string _name, uint _id, uint _age ) private{
    uint id = developers.push( Developer( _name, _id, _age ) ) - 1;
    ownerDevCount[msg.sender]++;
    devToOwner[id] = msg.sender;
    NewDeveloper(id, _name, _age);
}

function _generateRandomId( string _str ) private pure returns (uint){
    uint rand = uint(keccak256(_str));
    return rand;
}

function createRandomDeveloper( string _name, uint _age ) public payable {
    require(_age &gt; minAge);
    require(_age &lt; maxAge);
    require(msg.value == 5);
    uint randId = _generateRandomId( _name );
    _createDeveloper(_name, randId, _age );
}

}

Memory and Storage

In Solidity, there are two places where variables are stored: in storage or in memory. A variable stored in memory is temporary, it exists while the function is used, then it is discarded. A variable stored in storage exists permanently on the blockchain. Most of the time, you don't have to worry about where to store your variables, as Solidity handles it for you.

For example, state variables ( maxAge, minAge, Developer ), declared outside of functions, are stored in storage. Variables like randId, id, rand are stored in memory.

But, in some cases, you want to explicitly declare where to store certain variables. Solidity allows you to do that with memory and storagekeywords.




Deploy solidity contract with c#

I am developing an application on&nbsp;<strong><em>Ethereum</em></strong>&nbsp;blockchain. I use&nbsp;<strong><em>Solidity</em></strong>&nbsp;for contract and&nbsp;<strong><em>Nethereum c#</em></strong>&nbsp;library to connect to the contract. I am somehow new in Ethereum and it is my first app in blockchain!! I want to deploy my app in one&nbsp;<strong><em>TESTChain</em></strong>&nbsp;first,

I am developing an application on Ethereum blockchain. I use Solidity for contract and Nethereum c# library to connect to the contract. I am somehow new in Ethereum and it is my first app in blockchain!! I want to deploy my app in one TESTChain first,

The problem is that The C# code does not reply anything after send request for deploying of contract. here is my code

the contract is created well on remix and in running tab it works

  public class DeploymentTest : ContractDeploymentMessage
        {
      public static string BYTECODE = @"0x....";// removed it because of long string
  public DeploymentTest() : base(BYTECODE) { }
    }

  public async Task ConnectToTest()
        {
            var url = "https://github.com/Nethereum/TestChains";
            var pass = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7";
            var acc = new Account(pass);
            var chain = new Web3(acc, url);
            var deploymentMessage = new DeploymentTest();
            var deploymentHandler =  chain.Eth.GetContractDeploymentHandler&lt;DeploymentTest&gt;();

             // this point just waited and does not return anything
            var transactionReceipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage);
            var contractAddress = transactionReceipt.ContractAddress;

            }

Can any one help me, I don't insist in deploying with code, it can be happened by anyway but after deploying I need to connect it and call some functions. Thanks

EDITED

I downloaded the TESTChain network for windows and it works fine, it seems the default port is 8545 for http:localhost. but it still does not connect to chain

    var web3test = new Web3(); // also tried new Web3(http://localhost:8545);
var isMining = await web3test.Eth.Mining.IsMining.SendRequestAsync();
var accounts = await web3test.Eth.Accounts.SendRequestAsync();

is that problem with my connection? I disabled my MacAfee firewall completely.

EDITED 2

I changed my machine and it works on my another laptop, I cannot find the problem. I do not know if I just Uninstall the mcaffe will it be ok or not? has anybody any idea about the firewall prolems or other issues?