1.0.2 • Published 2 years ago
@dsnp/contracts v1.0.2
DSNP Contracts
The official DSNP interface and implementations.
Overview
Installation
$ npm install @dsnp/contracts
JavaScript ABI Usage
const announcer = require("@dsnp/contracts/abi/Announcer.json");
const annoucerABI = announcer.abi;
TypeScript ABI Usage
// Requires "resolveJsonModule": true in [tsconfig](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
import { abi as announcerABI } from "@dsnp/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/@dsnp/contracts/**/*.json --outDir ./types/typechain"
"build:web3types": "typechain --target=web3-v1 ./node_modules/@dsnp/contracts/**/*.json --outDir ./types/typechain"
- Make sure your
--outDir
is in tsconfig typeRoots. - Use the types:
// web3 example
import web3 from "web3";
import { Announcer } from "./types/typechain/Announcer";
import { abi as announcerABI } from "@dsnp/contracts/abi/Announcer.json";
const getAnnouncerContract = (contractAddress: string) => {
// web3 requires the type casts
return (new web3.eth.Contract(announcerABI, contractAddress) as any) as Announcer;
}
// ethersjsv5 example
import { Provider } from "@ethersproject/providers";
import { Announcer } from "./types/typechain/Announcer";
const getAnnouncerContract = (contractAddress: string, provider: Provider) => {
// TypeChain for Ethers provides factories
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 "@dsnp/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 ourdeploy.ts
script to our POA testnet defined in thehardhat.config.ts
Environment Variables
1. 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
0.0.0-f2a972
2 years ago
0.0.0-297343
2 years ago
1.0.2
2 years ago
0.0.0-f7c4cf
2 years ago
0.0.0-ed3576
2 years ago
0.0.0-e94a72
3 years ago
0.0.0-0bc3c3
3 years ago
0.0.0-bc313e
3 years ago
1.0.1
3 years ago
0.0.0-e7cefb
3 years ago
0.0.0-d64f10
3 years ago
1.0.0
3 years ago
0.0.0-5c945f
3 years ago
0.0.0-622366
3 years ago
0.0.0-cfa944
3 years ago
0.0.0-386b96
3 years ago
0.0.0-7eb972
3 years ago
0.1.0
3 years ago
0.0.0
3 years ago
0.0.0-9e8770
3 years ago
0.0.0-54f452
3 years ago
0.0.0-9c117e
3 years ago
0.0.0-d2067e
3 years ago
0.0.0-83d788
3 years ago
0.0.0-89312d
3 years ago
0.0.0-83c461
3 years ago
0.0.0-4b6581
3 years ago