**Browser Compiler for Solidity Contracts**
A browser compiler for solidity is a useful tool that allows us to compile solidity contracts in the browser. This technology is available at Remix Etherium.org, where we can find a wide range of solidity contracts and execute them on our own test blockchain.
**Solidity as its Own Language**
Solidity is a language that is similar to JavaScript, but with its own set of features and rules. As such, it requires some getting used to when working with it. However, with practice and patience, we can learn to code in solidity and build complex contracts using this powerful language.
**Importing Solidity Version**
When working with solidity contracts, we need to specify the version of solidity that we want to use. This is done by adding the `pragma` keyword at the top of our contract file. For example, let's say we want to use solidity version 0.16.4. We can add the following line to our contract file:
```
pragma solidity ^0.16.4;
```
**Creating a Simple Solidity Contract**
Now that we have specified the solidity version, we can create a simple solidity contract. Let's call this contract `TestContract`. We can define it as follows:
```
contract TestContract {
uint public value;
constructor() {
value = 0;
}
function set(uint _value) payable {
value = _value;
}
function notPayable(uint _value) {
value = _value;
}
}
```
In this contract, we have defined a single variable called `value` that is of type `uint`. We also have two functions: `set`, which allows us to set the value of `value`, and `notPayable`, which sets the value of `value` but does not accept any payments.
**The Constructor**
The constructor function in our contract is used to initialize the variables when the contract is created. In this case, we have defined a constructor that sets the value of `value` to 0.
**Getters and Setters**
In solidity, getters and setters are functions that allow us to access and modify the state of our contract. We can define them as follows:
```
function get() constant returns (uint) {
return value;
}
function set(uint _value) payable {
value = _value;
}
```
The `get` function allows us to retrieve the value of `value`, while the `set` function allows us to set the value of `value`.
**Setting and Getting Values**
Now that we have defined our contract, we can test it by creating a new instance of the contract on the Ethereum blockchain. We can use Remix Etherium.org to compile and deploy our contract.
Once our contract is deployed, we can execute its functions using the Remix console. Let's say we want to set the value of `value` to 20:
```
set(20)
```
This will call the `set` function with an input value of 20, setting the value of `value` to 20.
Next, let's try getting the current value of `value` using the `get` function:
```
get()
```
This will return the current value of `value`, which is now 20.
Finally, let's set the value of `value` again using the `set` function, but this time with a value of 300:
```
set(300)
```
This will call the `set` function with an input value of 300, setting the value of `value` to 300.
**Not Payable Function**
Let's try calling the `notPayable` function with an input value of 10:
```
notPayable(10)
```
This should return the current value of `value`, which is now 300.
However, because we have set the contract to not accept payments using the `notPayable` function, this will fail:
```
Error: Value must be paid for
```
As expected, the transaction fails because we cannot pay the value of 300.
**Conclusion**
In conclusion, we have seen how to create a simple solidity contract using Remix Etherium.org. We have defined a contract with a single variable and two functions, one that sets and gets the value, and another that sets the value but does not accept payments. We have also seen how to execute these functions on our own test blockchain. With practice and patience, we can build complex contracts using solidity and deploy them on the Ethereum blockchain.