#BlockChain-Etherum -DAPPS- Accessing Functions between contracts in Solidity.

I am using Remix-Solidity IDE for browser – https://ethereum.github.io/browser-solidity and have started learning solidity from udemy course- Ravinder Deol

In this post ,I will share how to access function between two contracts using solidity over etherum.

Step 1 : Creating a simple contract with Get/Set Function

Lets create a simple contract with a get and set function :

contract SampleContract1
{
uint myvar;
function SetVar(uint varvalue){
myvar = varvalue;
}
function GetVar() constant returns(uint)
{
return myvar;
}
}

Step 2 : Creating contract with constructor function that consumes other contracts

Lets create another contract where we got use function of contract1. In this contract we create constructor where we pass the adress of contract1.

contract SampleContract2
{
SampleContract1 instanceofsc1;
function SampleContract2(address addressofsc1) // constructor
{
instanceofsc1=SampleContract1(addressofsc1);
}

}

 

Step 3 : Accessing Function from other contract 

After we pass the address of contract1,we would be able to access the functions directly in contract2.

contract SampleContract2
{
SampleContract1 instanceofsc1;
function SampleContract2(address addressofsc1)
{
instanceofsc1=SampleContract1(addressofsc1);
}

function GetvarofSc1() constant returns(uint)
{
return instanceofsc1.GetVar();
}
}

Output in Solidity Browser :

Capture

 

#Bitcoin C#:Creating Bitcoin address using NBitCoin

1.Get NBitcoin from Nuget package.

Bitcoin Address : 

It is payment address which either begins with 1 or 3 ,its more of a combination of secure private and public key hash that is generated using cryptographic algorithm.To end user,its simply an address which is useful for sending/receiving bitcoins.

Generating Bitcoin using NBitcoin :


 Key bitcoin = new Key();
 var bitcoinaddress=bitcoin.PubKey.GetAddress(Network.TestNet);
 Console.WriteLine(bitcoinaddress);

Its as simple as that, you create a key and decide which network to generate bitcoin address.There are two networks MainNet(Real world) and TestNet(Test Environment).

 

MVC-Model View Controller

All Incoming Request to application is handled by Controller. The controller decides respective Model  and View.

Capture

for instance,if a request is made with URL “www.site.com/Home /About” ,then  following happens

1.Find Controller with name Home.

2. Find a Method named About in controller  which returns the respective View(View pulls data that has to be displayed from Model).

To summarize :

1.Model takes care of DataAcesss stuffs.

2.View takes care all of UI Components.

3.Controller maps the View and Model.