Skip to content

Instantly share code, notes, and snippets.

View MeiyappanKannappa's full-sized avatar

Karthik Meiyappan MeiyappanKannappa

View GitHub Profile
// My First Smart Contract
pragma solidity >0.5.0;
contract HelloWorld {
function get()public pure returns (string memory){
return 'Hello Contracts';
}
}
pragma solidity ^0.5.8;
contract ChocoLavaBank {
uint8 private clientCount;
mapping (address => uint) private balances;
address public owner;
// Log the event about a deposit being made by an address and its amount
event LogDepositMade(address indexed accountAddress, uint amount);
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(8000, () => {
console.log(`Example app listening at http://localhost:${8000}`)
// SMART CONTRACT CONFIG
let fs = require("fs");
let Web3 = require('web3'); // https://www.npmjs.com/package/web3
// Create a web3 connection to a running geth node over JSON-RPC running at
// http://localhost:7545
let web3 = new Web3();
web3.setProvider(new web3.providers.HttpProvider('http://localhost:7545'));
app.get('/getBalance', (req, res) => { // new
var myContract = new web3.eth.Contract(contracts.abi, process.env.CONTRACTS_ADDRESS, {
from: req.query.account_id, // default from address
gasPrice: '3000000' // default gas price in wei, 20 gwei in this case
});
myContract.methods.balance().call({from: req.query.account_id,gasPrice: '3000000'})
.then(function(result){
console.log(result+' wei')
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Headers', "*");
@MeiyappanKannappa
MeiyappanKannappa / reverse-proxy.yaml
Created March 27, 2022 09:10
Envoy-GRPC-Reverse Proxy Bridge
admin:
address:
socket_address:
address: 0.0.0.0
port_value: 9901
static_resources:
listeners:
- name: listener_0
address:
socket_address:
@MeiyappanKannappa
MeiyappanKannappa / app.js
Created March 27, 2022 09:43
Node-Express Server side API for envoy grpc reverse bridge
const bodyParser= require('body-parser')
const express = require('express')
const app = express()
const port = 80
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto';
const protobuf = require('protobufjs');
app.use(bodyParser.json({
verify: (req, res, buf) => {
@MeiyappanKannappa
MeiyappanKannappa / greeter_client.js
Created March 27, 2022 09:44
Grpc Client code to connect to HTTP1.1 server via Envoy proxy
var PROTO_PATH = __dirname + '/../../protos/helloworld.proto';
var parseArgs = require('minimist');
var grpc = require('@grpc/grpc-js');
var protoLoader = require('@grpc/proto-loader');
var packageDefinition = protoLoader.loadSync(
PROTO_PATH,
{keepCase: true,
longs: String,
enums: String,
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
package com.example.shedlockdemo;
import com.authzed.api.v1.Core;
import com.authzed.api.v1.PermissionService;
import com.authzed.api.v1.PermissionsServiceGrpc;
import com.authzed.grpcutil.BearerToken;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;