contract typechain for developing elysia dapp.
Do not need ABI file and to define any types of contract with this package!
Supported contracts
- StakingPool (StakingPool__factory)
- MoneyPool (MoneyPool__factory)
- IncentivePool (IncentivePool__factory)
- ERC20 (ERC20__factory)
and others are listed in src/factories
yarn add @elysia-dev/contract-typechain
import React, { useMemo } from 'react';
import { useWeb3React } from '@web3-react/core';
import { StakingPool__factory } from "@elysia-dev/contract-typechain";
const StakingModal: React.FunctionComponent = () => {
const { account, library } = useWeb3React();
const contract = useMemo(() => {
return StakingPool__factory.connect(
"0xDF409737E31475Ec46e13335Ad5370c551b97D12",
library.getSigner()
)
}, [library])
const stake = async (amount: BigNumber) => {
const tx = await contract.stake(
amount
)
/* tx is typed well
interface TransactionResponse extends Transaction {
hash: string;
blockNumber?: number,
blockHash?: string,
timestamp?: number,
confirmations: number,
from: string;
raw?: string,
wait: (confirmations?: number) => Promise<TransactionReceipt>
};
*/
it(tx){
console.log(tx.hash)
/*
tx.wait().then(() => {
})
*/
} else {
console.log("Tx is not created")
}
}
...
return (
...
)
}
Assume thats there is a singer instance(ether.js signer).
import { MoneyPool__factory } from "@elysia-dev/contract-typechain";
const signer = ... // this instance is created with provider & signer secret key
const contract = MoneyPool__factory.connect(
"address",
signer,
)
const deposit = async () => {
}
- yarn build
- yarn build:d
- update pacakge version number
- npm publish