Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2017 14:28
Show Gist options
  • Save anonymous/83bef618463cbb8061eac48f4ebe52f4 to your computer and use it in GitHub Desktop.
Save anonymous/83bef618463cbb8061eac48f4ebe52f4 to your computer and use it in GitHub Desktop.
/* GENERATED BY TYPECHAIN VER. 0.1.0 */
import { BigNumber } from "bignumber.js";
import {
TypeChainContract,
promisify,
ITxParams,
IPayableTxParams,
DeferredTransactionWrapper
} from "./typechain-runtime";
export class example extends TypeChainContract {
public readonly rawWeb3Contract: any;
public constructor(web3: any, address: string | BigNumber) {
const abi = [
{
constant: true,
inputs: [{ name: "_owner", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{ name: "_to", type: "address" },
{ name: "_value", type: "uint256" }
],
name: "transfer",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function"
}
];
super(web3, address, abi);
}
static async createAndValidate(
web3: any,
address: string | BigNumber
): Promise<example> {
const contract = new example(web3, address);
const code = await promisify(web3.eth.getCode, [address]);
if (code === "0x0") {
throw new Error(`Contract at ${address} doesn't exist!`);
}
return contract;
}
public balanceOf(_owner: BigNumber | string): Promise<BigNumber> {
return promisify(this.rawWeb3Contract.balanceOf, [_owner.toString()]);
}
public transferTx(
_to: BigNumber | string,
_value: BigNumber | number
): DeferredTransactionWrapper<ITxParams> {
return new DeferredTransactionWrapper<ITxParams>(this, "transfer", [
_to.toString(),
_value.toString()
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment