File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ typings/
6363# build
6464dist
6565* .js
66+ ! examples /* .js
6667* .mjs
6768* .d.ts
6869* .ts.map
Original file line number Diff line number Diff line change 1+ # dev-kit-js examples
2+
3+ ## Usage
4+
5+ ` package.json `
6+
7+ ```
8+ {
9+ "name": "devkit-examples-sandbox",
10+ "version": "0.0.1",
11+ "type": "module",
12+ "license": "MIT",
13+ "scripts": {
14+ "start": "node index.js"
15+ },
16+ "dependencies": {
17+ "@devprotocol/dev-kit": "^5.8.1",
18+ "ethers": "^5.5.2"
19+ }
20+ }
21+ ```
22+
23+ copy the script file you want to run into index.js.
24+ Then ` yarn install ` to prepare for execution.
25+
26+ ```
27+ $ cp xxx.js index.js
28+ $ yarn install
29+ $ tree -L 1
30+ .
31+ ├── index.js
32+ ├── node_modules
33+ ├── package.json
34+ └── yarn.lock
35+ ```
36+
37+ run example script (with local ethereum node. like this ` http://localhost:8545 ` ):
38+
39+ ```
40+ $ yarn start
41+ ```
42+
43+ run example script (with infura)
44+ ```
45+ $ WEB3_PROVIDER_URL=https://mainnet.infura.io/v3/xxxx yarn start
46+ ```
Original file line number Diff line number Diff line change 1+ import { ethers } from 'ethers'
2+ import { contractFactory , addresses } from '@devprotocol/dev-kit'
3+
4+ // use main net
5+ const registryContractAddress = addresses . eth . main . registry
6+ const provider = new ethers . providers . JsonRpcProvider ( process . env . WEB3_PROVIDER_URL )
7+ const contract = contractFactory ( provider )
8+ const propertyAddress = '0xac1AC9d00314aE7B4a7d6DbEE4860bECedF92309'
9+ const lockupContractAddress = await contract . registry ( registryContractAddress ) . lockup ( )
10+
11+ const propertyStakingAmount = await contract . lockup ( lockupContractAddress ) . getPropertyValue ( propertyAddress )
12+ const stakingAmount = ethers . BigNumber . from ( propertyStakingAmount ) . div ( new ethers . BigNumber . from ( 10 ) . pow ( 18 ) )
13+ console . log ( `${ propertyAddress } 's staking amount is ${ stakingAmount . toBigInt ( ) } DEV` )
14+
15+ const propertyRewards = await contract . lockup ( lockupContractAddress ) . calculateRewardAmount ( propertyAddress )
16+ const reward = ethers . BigNumber . from ( propertyRewards [ 0 ] ) . div ( new ethers . BigNumber . from ( 10 ) . pow ( 36 ) )
17+ console . log ( `${ propertyAddress } 's rewards is ${ reward . toBigInt ( ) } DEV` )
Original file line number Diff line number Diff line change 1+ import { getStats } from '@devprotocol/dev-kit'
2+
3+ const stats = await getStats ( )
4+ console . log ( stats )
Original file line number Diff line number Diff line change 1+ import { ethers } from 'ethers'
2+ import { contractFactory , addresses } from '@devprotocol/dev-kit'
3+
4+ // use main net
5+ const contractAddress = addresses . eth . main . sTokens
6+ const provider = new ethers . providers . JsonRpcProvider ( process . env . WEB3_PROVIDER_URL )
7+ const contract = contractFactory ( provider )
8+ const propertyAddress = '0xac1AC9d00314aE7B4a7d6DbEE4860bECedF92309'
9+
10+ const getSTokenIdsByPropertyAddress = async ( contract , propertyAddress ) => {
11+ const res = await contract . sTokens ( contractAddress ) . positionsOfProperty ( propertyAddress )
12+ return res
13+ }
14+
15+ const getSTokenPositions = async ( contract , sTokenId ) => {
16+ const res = await contract . sTokens ( contractAddress ) . positions ( sTokenId )
17+ return res
18+ }
19+
20+ const getSTokenRewards = ( contract , sTokenId ) => {
21+ return contract . sTokens ( contractAddress ) . rewards ( sTokenId )
22+ }
23+
24+
25+ // get stoken ids
26+ const sTokenIds = await getSTokenIdsByPropertyAddress ( contract , propertyAddress )
27+
28+ // get postions data by stoken id
29+ const res = await Promise . all ( sTokenIds . map ( async ( sTokenId ) => {
30+ const positions = await getSTokenPositions ( contract , sTokenId )
31+ const rewards = await getSTokenRewards ( contract , sTokenId )
32+ return { sTokenId, positions, rewards }
33+ } ) )
34+ console . log ( res )
You can’t perform that action at this time.
0 commit comments