-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vda-token-client] Initial version (#450)
- Loading branch information
Showing
20 changed files
with
1,745 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## These are used for test only. | ||
PRIVATE_KEY = "<Input the private key of the wallet>" | ||
RPC_URL="<Input the RPC_URL of chain that contract deployed>" | ||
|
||
# Test chain : One of "POLAMOY", "POLPOS", "DEVNET" | ||
BLOCKCHAIN_ANCHOR = "POLAMOY" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#Ignore all files starting with "." | ||
.* | ||
!/.gitignore | ||
|
||
# node_modules in all sub directories | ||
**node_modules | ||
|
||
# build | ||
dist/ | ||
lib/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
2023-07-12 (v) | ||
------------------- | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
# VDA Token Client | ||
|
||
A client library to managet Verida Tokens | ||
|
||
## Dependencies | ||
This package dependes on the following `verida-js` packages: | ||
- `@verida/types` | ||
- `@verida/helpers` | ||
- `@verida/vda-common` | ||
- `@verida/vda-web3` | ||
|
||
And dependes on the following packages for test: | ||
- `@verida/vda-common-test` | ||
|
||
## Installation | ||
|
||
``` | ||
yarn add @verida/vda-token-client | ||
``` | ||
|
||
## Usage | ||
|
||
There are 2 classes of `VeridaTokenClient` and `VeridaTokenOwner`.<br/> | ||
- `VeridaTokenClient` is for general users to mange VDA tokens. | ||
- `VeridaTokenOwner` adds the owner-specific functions to the `VeridaTokenClient`. | ||
|
||
These classes can be run in 2 modes of __*read-only*__ and __*read & write*__.<br/> | ||
If you provided `privateKey` field in the configuration while creating the instance, it runs in __*read & write*__ mode, otherwise it runs in __*read-only*__ mode. | ||
|
||
In the __*read-only*__ mode, it can calls only the `view` functions of the contract. | ||
|
||
### Read Only | ||
|
||
Setup the library in `read only`: | ||
|
||
```ts | ||
import { VeridaTokenClient } from '@verida/vda-token-client' | ||
import { BlockchainAnchor } from '@verida/types' | ||
|
||
// Create token Client | ||
const blockchainAnchor = BlockchainAnchor.POLAMOY; | ||
const rpcUrl = `<Your rpc url>`; // This is optional | ||
const tokenClient = await VeridaTokenClient.CreateAsync({ | ||
blockchainAnchor, | ||
rpcUrl | ||
}) | ||
``` | ||
|
||
#### *Example:* Get total supply | ||
|
||
```ts | ||
const value:BigNumber = await tokenClient.totalSupply(); | ||
``` | ||
|
||
### Read and Write | ||
|
||
```ts | ||
import { VeridaTokenClient } from '@verida/vda-token-client' | ||
import { BlockchainAnchor } from '@verida/types' | ||
|
||
const blockchainAnchor = BlockchainAnchor.POLAMOY; | ||
const rpcUrl = `<Your rpc url>`; // This is optional | ||
const privateKey = `<Input your wallet private key>`; | ||
const tokenClient = await VeridaTokenClient.CreateAsync({ | ||
blockchainAnchor, | ||
privateKey, | ||
rpcUrl | ||
}) | ||
``` | ||
|
||
#### *Example:* Transfer token | ||
|
||
```ts | ||
const to = `0x...`; // Recipient address | ||
const amount = BigNumber.from(10); | ||
await tokenClient.transfer(to, amount); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# VDA Token Client Test | ||
|
||
Here explains stuffs related to test this `@verida/vda-token-client` package. | ||
|
||
## owner.test.ts | ||
- Only the contract owner can test this file | ||
|
||
## read.test.ts | ||
- Anybody can test this file | ||
|
||
## write.test.ts | ||
Please check following before run this test: | ||
- Token balances of following addresses:<br> | ||
```ts | ||
0x8Ec5df9Ebc9554CECaA1067F974bD34735d3e539: More than `AMOUNT_SEND`(=1000) tokens | ||
0xE3A441c4e699433FCf1262246Cf323d8e4302998: More than `AMOUNT_APPROVE`(=1000) tokens | ||
``` | ||
|
||
- Enough Matic in following addresses: | ||
```ts | ||
0x8Ec5df9Ebc9554CECaA1067F974bD34735d3e539, | ||
0xE3A441c4e699433FCf1262246Cf323d8e4302998 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "@verida/vda-token-client", | ||
"version": "0.1.0", | ||
"description": "Client to manage Verida token", | ||
"main": "build/src/index.js", | ||
"types": "build/src/index.d.ts", | ||
"files": [ | ||
"build/src" | ||
], | ||
"directories": { | ||
"src": "src", | ||
"test": "tests" | ||
}, | ||
"license": "Apache-2.0", | ||
"keywords": [], | ||
"scripts": { | ||
"tests": "ts-mocha './test/**/*.tests.ts'", | ||
"test": "ts-mocha --timeout 200000", | ||
"lint": "gts lint", | ||
"clean": "gts clean", | ||
"compile": "rm -rf build && tsc", | ||
"build": "rm -rf build && tsc", | ||
"fix": "gts fix", | ||
"prepare": "npm run compile" | ||
}, | ||
"dependencies": { | ||
"@ethersproject/providers": "^5.7.2", | ||
"@verida/helpers": "^4.0.0-alpha-1", | ||
"@verida/types": "^4.0.0-alpha-1", | ||
"@verida/web3": "^4.0.0-alpha-1", | ||
"axios": "^0.27.2", | ||
"ethers": "^5.7.0" | ||
}, | ||
"devDependencies": { | ||
"@verida/vda-common-test": "^4.0.0-alpha-1", | ||
"dotenv": "^16.0.3", | ||
"gts": "^3.1.0", | ||
"mocha": "^10.1.0", | ||
"ts-mocha": "^10.0.0", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.4" | ||
} | ||
} |
Oops, something went wrong.