Skip to content

Instantly share code, notes, and snippets.

View kermankohli's full-sized avatar
✌️

Kerman kermankohli

✌️
View GitHub Profile
@kermankohli
kermankohli / Contract.mustache
Last active October 28, 2018 07:13
Contract.mustache
import { promisify } from '@0xproject/utils';
import { BigNumber } from 'bignumber.js';
import * as Web3 from 'web3';
import { {{contractName}} as ContractArtifacts } from '../abi/ts/{{contractName}}';
import { BaseContract, CONTRACT_WRAPPER_ERRORS } from '@your-project/base-contract';
import { TxData, TxDataPayable, classUtils } from '@your-project/types';
import { Web3Utils } from '../../utils/Web3Utils';
@kermankohli
kermankohli / tsconfig.json
Created October 28, 2018 06:38
Types TSConfig
{
"compilerOptions": {
"outDir": "./dist",
"sourceMap": true,
"noImplicitAny": false,
"lib": ["dom", "es2015", "es2016", "es2017"],
"module": "commonjs",
"baseUrl": "src/",
"rootDir": "src/",
"target": "es5",
@kermankohli
kermankohli / package.json
Created October 28, 2018 06:39
Types Package JSON
{
"name": "@your-project/types",
"version": "0.2.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "rimraf rm -rf dist",
"build": "npm run clean && tsc"
},
@kermankohli
kermankohli / index.ts
Created October 28, 2018 06:42
Types File
import { BigNumber } from "bignumber.js";
import * as _ from "lodash";
export interface TxData {
from?: string;
gas?: BigNumber;
gasPrice?: BigNumber;
nonce?: BigNumber;
}
@kermankohli
kermankohli / tsconfig.json
Created October 28, 2018 06:45
Root TSConfig
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["dom", "es2015", "es2016", "es2017"],
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"noImplicitReturns": true,
@kermankohli
kermankohli / tsconfig.json
Created October 28, 2018 06:51
Base Contract TSConfig
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": ["dom", "es2015", "es2016", "es2017"],
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
"downlevelIteration": true,
"noImplicitReturns": true,
@kermankohli
kermankohli / package.json
Created October 28, 2018 06:55
Base Contract Package JSON
{
"name": "@your-project/base-contract",
"version": "0.2.0",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"clean": "rimraf rm -rf dist",
"build": "npm run clean && tsc"
@kermankohli
kermankohli / index.ts
Created October 28, 2018 06:57
Base Contract Src
import * as _ from "lodash";
import * as Web3 from "web3";
import { BigNumber } from "bignumber.js";
import { TxData, TxDataPayable } from '@your-project/types';
export const CONTRACT_WRAPPER_ERRORS = {
CONTRACT_NOT_FOUND_ON_NETWORK: (contractName: string, networkId: number) =>
`Unable to find address for contract ${contractName} on network with id ${networkId}`,
@kermankohli
kermankohli / call.mustache
Created October 28, 2018 07:03
Partials - call
public {{this.name}} = {
async callAsync(
{{> typed_params inputs=inputs}}
defaultBlock?: any,
): Promise<{{> return_type outputs=outputs}}> {
const self = this as {{contractName}}Contract;
const result = await promisify<{{> return_type outputs=outputs}}>(
self.web3ContractInstance.{{this.name}}.call,
self.web3ContractInstance,
)(
@kermankohli
kermankohli / params.mustache
Created October 28, 2018 07:04
Partials - Params
{{#each inputs}}
{{name}},
{{/each}}