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

photo by — Jan Kopřiva
  1. Introduction
  2. Setting Environment
  3. Creating a smart contract using Vyper
  4. Deploying a smart contract to Ganache
  5. Interacting with smart contracts
  6. Interacting with other smart contracts
  7. Compiling code programmatically

What is Vyper?

Why Vyper?

  • Security: It should be possible and natural to build secure smart contracts in Vyper.
  • Language and compiler simplicity: The language and the compiler implementation should strive to be simple.
  • Auditability: Vyper code should be maximally human-readable. Furthermore, it should be maximally difficult to write a misleading code. Simplicity for the reader is more important than simplicity for the writer, and simplicity for readers with low prior experience with Vyper (and low prior experience with programming in general) is particularly important.
  • Bounds and overflow checking: On array accesses and arithmetic.
  • Support for signed integers and decimal fixed-point numbers
  • Decidability: It is possible to compute a precise upper bound for the gas consumption of any Vyper function call.
  • Strong typing
  • Small and understandable compiler code
  • Limited support for pure functions: Anything marked constant is not allowed to change the state.
$ python3 -m pip install --user virtualenv
$ pip install vyper
$ virtualenv -p python3.6 vyper-venv
$ source vyper-venv/bin/activate
(vyper-venv) $ pip install vyper
(vyper-venv) $ vyper --version
(vyper-venv) $ vyper hello.vy
(vyper-venv) $ vyper -f json hello.vy
(vyper-venv) $ vyper -f json,bytecode hello.vy
abi, json
  1. Create a directory and initialize it with truffle init as follows:
$ mkdir hello_project
$ cd hello_project
$ truffle init
module.exports = { 
networks: {
"development": {
network_id: "*",
host: "",
port: 8545 // port at Ganache running
$ mkdir -p build/contracts
$ cd build/contracts
var Hello = artifacts.require("Hello");
module.exports = function(deployer){
$ truffle migrate
truffle output
$ truffle console
truffle output
truffle(development)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(function(instance){return; });'Satoshi Nakamoto'
truffle(development)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(function(instance) { return instance.change_name(“Vitalik Buterin”), { from: “0xb28Fc17791bf66719FBFCc65846B01Fe2726e9E2” } });
{ from: ‘0xb28Fc17791bf66719FBFCc65846B01Fe2726e9E2’ }
truffle(development)>“0x4AB3935Df0E224771663984f3617F1a78beA4E8D”).then(function(instance){return; });‘Vitalik Buterin’
var Hello = artifacts.require("Hello");
module.exports = function(deployer){
"contractName": "Hello",
"abi": <your Hello smart contract's interface>,
"bytecode": "<your Hello smart contract's bytecode>"
var Donation = artifacts.require("Donation");
module.exports = function(deployer) {
"contractName": "Donation",
"abi": <your Donation smart contract's interface>,
"bytecode": "<your Donation smart contract's bytecode>"
$ truffle migrate --reset
truffle output
$ truffle console
truffle(development)>“0x25aFF89B8a72aB4Ba6F4C831f5B1375f9BCe76A9”).then(function(instance) { return“0x772138489eD34095FBA6a0Af70d3C9115813CFcA”); } );
(vyper-venv) $ python compiler.vy

Leave a Comment