0% found this document useful (0 votes)
20 views5 pages

Blockchain Lab SOHAM KORE Exp 3

blockchain

Uploaded by

vu4s2122008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Blockchain Lab SOHAM KORE Exp 3

blockchain

Uploaded by

vu4s2122008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name – Soham Kore BE IT B

ID No- VU4F2021115 Batch – B


Experiment No. 3

Aim: To study Deployment and publish smart contracts on Ethereum test network.

Theory: A brief description of all contents used for developing smart contract

Smart contracts :

Smart contracts are blocks of code that reside on the blockchain. It is like an Ethereum account but
there is a critical difference between an external account and a smart contract. Unlike a smart
contract, an external account can connect to multiple Ethereum networks (Goerlitestnet, mainnet,
etc.) whereas a smart contract is only specific to one individual network (the network it is deployed
on). When a smart contract is deployed, it creates an instance (contract account) on the network.
One can create multiple instances of a smart contract on the network or multiple networks.
Deployment of a smart contract is done by sending a transaction to the network with bytecode.

Deploying To A Local Network


An emulator can be used to deploy a smart contract on a local network eg. Ganache-cli. It takes care
of everything and the user doesn’t have to worry about the security and the gas amount required for
transactions since everything is happening on a local test network. All one has to do is pass the
ganache provider as an argument to the web3 instance(web3 facilitates the connection between the
blockchain network and the js application).

Deploying To Actual Ethereum Network:


Before deploying a smart contract to an actual Ethereum network make sure the account has some
ether in it. Deploying a contract is like sending a transaction and it needs some gas amount to
process. Unlike deploying on a local network, transactions will take some time to complete
(anywhere between 15 seconds to 5 minutes). Web3 is used to interact with the network the same
way it is done in local deployment except customize the provider that will be passed into the web3
instance. Instead of creating our own node that connects to the Ethereum network, one can use a
developer platform with RPC endpoints like Infura or Alchemy. With one of these accounts, you
have an API key that gives access to their Infura / Alchemy blockchain nodes that are already
hosted on the Ethereum network. Simply sign-up for Infura and get an endpoint that will be used in
the code to deploy the smart contract. The below tutorial shows a smart contract being deployed
with Infura. For a smart contract tutorial using tools like Alchemy (ethers.js, Hardhat, Solidity, and
Metamask), refer to this basic tutorial – “Hello World Smart Contract“.

Practical code with steps :

How to Deploy the Smart Contract


After successful compilation of smart contracts in experiment 2 ,now we deploy the contract.
Click on the fourth icon in the side menu:

Select Remix VM (London) for the ENVIRONMENT. It has ten (10) accounts with 100 dummy
ethers each that you may use for test purposes. Then click the Deploy button:
Now when you scroll to the bottom, you will find the Blockchain contract under Deployed
Contracts. Click the arrow by the deployed contract name to see the functions of the contract that
you can interact with.

There are three (3) functions in the image above that match the three (3) functions we defined in our
smart contract. Remix automatically creates a UI for you to test your contracts as soon as you
deploy them.
How to Test the Smart Contract
We will now test the functions we created to see how they respond.

How to test the addBlockToChain function


To test the addBlockToChain function, click the caret (^) icon by the side of the function button and
input box. That drops down a form. Fill in 10 for the amount, and fill in one of the ten 10 account
addresses for the recipient:

Click the transact button.


Note that you cannot send funds to the same address you used to deploy the contract. You must
choose a different account.
How to test the getChain function

Click the get Chain button to reveal the blocks in the chain so far:
It returns a tuple, which is a kind of array. Recall that chain is supposed to be an array containing a
list of blocks.

How to test the getChainCount function


To get the number of blocks added, click the getChainCount button:

And just as we defined it, it returns a unit. There is just one item in the chain for now, but as you
keep adding more blocks, the number will increase.

Conclusion: Hence, we have successfully Deployed and publish smart contracts on Ethereum test
network.

You might also like