Implementing Smart Contracts Using Vyper — A Python Approach | by Abhishek Chauhan | Mar, 2022

photograph by — Jan Kopřiva
  1. Introduction
  2. Setting Surroundings
  3. Creating a sensible contract utilizing Vyper
  4. Deploying a sensible contract to Ganache
  5. Interacting with good contracts
  6. Interacting with different good contracts
  7. Compiling code programmatically

What’s Vyper?

Why Vyper?

  • Safety: It must be potential and pure to construct safe good contracts in Vyper.
  • Language and compiler simplicity: The language and the compiler implementation ought to try to be easy.
  • Auditability: Vyper code must be maximally human-readable. Moreover, it must be maximally tough to jot down deceptive code. Simplicity for the reader is extra vital than simplicity for the author, and ease for readers with low prior expertise with Vyper (and low prior expertise with programming usually) is especially vital.
  • Bounds and overflow checking: On array accesses and arithmetic.
  • Help for signed integers and decimal fixed-point numbers
  • Decidability: It’s potential to compute a exact higher certain for the gasoline consumption of any Vyper operate name.
  • Robust typing
  • Small and comprehensible compiler code
  • Restricted assist for pure capabilities: Something marked fixed is just not allowed to alter the state.
$ python3 -m pip set up --user virtualenv
$ pip set up vyper
$ virtualenv -p python3.6 vyper-venv
$ supply vyper-venv/bin/activate
(vyper-venv) $ pip set up vyper
(vyper-venv) $ vyper --version
whats up.vy
(vyper-venv) $ vyper whats up.vy
(vyper-venv) $ vyper -f json whats up.vy
(vyper-venv) $ vyper -f json,bytecode whats up.vy
abi, json
  1. Create a listing and initialize it with truffle init as follows:
$ mkdir hello_project
$ cd hello_project
$ truffle init
module.exports =  
network_id: "*",
host: "",
port: 8545 // port at Ganache working

$ mkdir -p construct/contracts
$ cd construct/contracts

var Hiya = artifacts.require("Hiya");
module.exports = operate(deployer)
$ truffle migrate
truffle output
$ truffle console
truffle output
truffle(improvement)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(operate(occasion)return; );'Satoshi Nakamoto'
truffle(improvement)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(operate(occasion)  return occasion.change_name(“Vitalik Buterin”),  from: “0xb28Fc17791bf66719FBFCc65846B01Fe2726e9E2”  );
 from: ‘0xb28Fc17791bf66719FBFCc65846B01Fe2726e9E2’ 
truffle(improvement)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(operate(occasion)return; );‘Vitalik Buterin’
var Hiya = artifacts.require("Hiya");
module.exports = operate(deployer)

"contractName": "Hiya",
"abi": <your Hiya good contract's interface>,
"bytecode": "<your Hiya good contract's bytecode>"
var Donation = artifacts.require("Donation");
module.exports = operate(deployer)

"contractName": "Donation",
"abi": <your Donation good contract's interface>,
"bytecode": "<your Donation good contract's bytecode>"
$ truffle migrate --reset
truffle output
$ truffle console
truffle(improvement)>“0x25aFF89B8a72aB4Ba6F4C831f5B1375f9BCe76A9”).then(operate(occasion)  return“0x772138489eD34095FBA6a0Af70d3C9115813CFcA”);  );
(vyper-venv) $ python compiler.vy

More Posts