Skip to content

Instantly share code, notes, and snippets.

View parv3213's full-sized avatar

Parv Garg parv3213

View GitHub Profile
@parv3213
parv3213 / initialSetup.js
Last active December 6, 2020 08:56
Understanding Web3 Events
const Web3 = require("web3")
const tokenABI=[{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_upgradedAddress","type":"address"}],"name":"deprecate","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"deprecated","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_evilUser","type":"address"}],"name":"addBlackList","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{
@parv3213
parv3213 / eventOnce.js
Created December 6, 2020 08:57
Once web3 event function
const eventOnce = () => {
contractInstance.once("Transfer", (error, event) => {
if(!error) console.log(event);
else console.log(`Error: ${error}`);
})
}
eventOnce();
@parv3213
parv3213 / eventEvents.js
Last active December 6, 2020 09:56
Events web3 event function
const eventEvents = () => {
console.log(`Listening Transfer events`);
contractInstance.events
.Transfer()
.on("data", (event) => console.log(event))
.on("error", (error) => console.log(error));
}
eventEvents();
@parv3213
parv3213 / eventGetPastEvents.js
Created December 6, 2020 10:09
GetPastEvents web3 event function
const eventGetPastEvents = () => {
console.log(`Returns all the past events`);
contractInstance.getPastEvents("Transfer", (error, event) => {
if(!error) console.log(event);
else console.log(`Error: ${error}`);
})
}
eventGetPastEvents();
@parv3213
parv3213 / Voting.sol
Last active May 22, 2021 19:32
Voting smart contract with candidate information
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.0;
// We have to specify what version of compiler this code will compile with
contract Voting {
/* mapping field below is equivalent to an associative array or hash.
The key of the mapping is candidate name stored as type bytes32 and value is
an unsigned integer to store the vote count
*/
@parv3213
parv3213 / gist:55fdbdf77757f2f3a91e1da24afb0a7a
Created August 17, 2021 15:43
did:3:kjzl6cwe1jw147zy7khmpydara8b27zfzc6ah8wndsyik3ijioeir5e53uk7cjv
did:3:kjzl6cwe1jw147zy7khmpydara8b27zfzc6ah8wndsyik3ijioeir5e53uk7cjv
@parv3213
parv3213 / GnosisInteraction.ts
Created October 13, 2021 11:30
Interact with Gnosis Safe using Gnosis Transaction Service
import { ethers } from 'hardhat';
import Safe, { EthersAdapter } from '@gnosis.pm/safe-core-sdk';
import { SafeTransactionDataPartial } from '@gnosis.pm/safe-core-sdk-types';
import SafeServiceClient, {
SafeInfoResponse,
} from '@gnosis.pm/safe-service-client';
const SUPPORTED_NETWORKS: number[] = [4]; // Array of supported networks
const GNOSIS_SAFE_ADDRESS: string =
'0xF16cAC48d46135247CC2f1e5054d0B2b0f0000AF'; // Address of Gnosis Safe
@parv3213
parv3213 / Hardhat fork
Last active March 18, 2024 13:35
Hardhat Fork
hardhat: {
accounts: [
{
balance: '100000000000000000000000000000',
privateKey: `0x${PRIVATE_KEY}`,
},
],
forking: {
url: 'https://polygon-mumbai.infura.io/v3/${INFURA_API_KEY}',
blockNumber: xxxx,
@parv3213
parv3213 / encodeDecode.ts
Created April 25, 2024 07:30
Simple metadata encode decode
import { ethers } from 'hardhat'
async function main() {
const abiCoder = ethers.AbiCoder.defaultAbiCoder()
const a = abiCoder.encode(
['string'],
[
JSON.stringify({
name: 'A-valid-TeamName',
}),
],
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract BulkSender {
// This function sends specified amounts of ETH to multiple addresses.
function sendETH(address[] memory recipients, uint256 value) public payable {
// Send ETH to each recipient
for (uint256 i = 0; i < recipients.length; i++) {
(bool sent, ) = recipients[i].call{value: value}("");
require(sent, "Failed to send ETH");