DSNP Contracts
The official DSNP interface and implementations.
Overview
Installation
$ npm install @unfinishedlabs/contracts
JavaScript ABI Usage
const announcer = require("@unfinishedlabs/contracts/abi/Announcer.json");
const annoucerABI = announcer.abi;
TypeScript ABI Usage
import { abi as announcerABI } from "@unfinishedlabs/contracts/abi/Announcer.json";
TypeScript Contract Types
To maintain types, it is suggested to use TypeChain.
- Follow the install directions and add the correct package for your toolset.
- Add a postinstall or other step to run typechain:
"postinstall": "typechain --target=(ethers-v5|web3-v1|other...) ./node_modules/@unfinishedlabs/contracts/**/*.json --outDir ./types/typechain"
"build:web3types": "typechain --target=web3-v1 ./node_modules/@unfinishedlabs/contracts/**/*.json --outDir ./types/typechain"
- Make sure your
--outDir
is in tsconfig typeRoots. - Use the types:
import web3 from "web3";
import { Announcer } from "./types/typechain/Announcer";
import { abi as announcerABI } from "@unfinishedlabs/contracts/abi/Announcer.json";
const getAnnouncerContract = (contractAddress: string) => {
return (new web3.eth.Contract(announcerABI, contractAddress) as any) as Announcer;
}
import { Provider } from "@ethersproject/providers";
import { Announcer } from "./types/typechain/Announcer";
const getAnnouncerContract = (contractAddress: string, provider: Provider) => {
return Announcer__factory.connect(contractAddress, provider);
}
Contract Usage
Once installed, you can use the contracts in the library by importing them:
pragma solidity ^0.8.0;
import "@unfinishedlabs/contracts/IAnnounce.sol";
contract MyAnnouncer is IAnnounce {
// ...
}
Development
We are using hardhat to compile and deploy the contracts
Key Commands and Tasks
Basic Command List:
npm install
npm run clean
- clears the cache and deletes all artifactsnpm run compile
- compiles the entire project, building all artifactsnpm run console
- opens a hardhat consolenpm run test
- runs mocha testsnpm run lint
- to run the linternpm run format
- to trigger formattingnpm run deploy:testnet
- deploys our deploy.ts
script to our POA testnet defined in the hardhat.config.ts
Environment Variables
- create a
.env
file and set values for all variables in .env.sample
Env Variable Name | Description |
---|
LOCAL_NETWORK_PRIVATE_KEY | private key for an account we have on our local network that has eth. |
STAGENET_ACCOUNT_PRIVATE_KEY | private key for an account we have on our test network that has eth. |
STAGENET_CHAIN_URL | Url to connect to tesnet |
VALIDATOR1 | hex prefixed address for validator running on node called liberty-chain |
VALIDATOR2 | hex prefixed address for validator running on node called liberty-chain1 |
BOOTNODE | enode address of the node our node would like to connect to |
Accounts
Deployments
Ports
Development
- This repo uses Hardhat + ethers for interfacing with Ethereum,
- Waffle for testing,
- And Truffle or truffle-style for contract migration.