Skip to content

Commit

Permalink
[vda-token-client] Initial version (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
ITStar10 authored Jul 24, 2024
1 parent ca3d324 commit 955807c
Show file tree
Hide file tree
Showing 20 changed files with 1,745 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/types/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
2024-07-15 (v.4.0.0)
-------------------

- Removed `web3` parameter in `Web3SelfTransactionConfig`
- Support BlockchainAnchor and Verida Network refactor

2023-12-26 (v.3.0.0)
Expand Down
2 changes: 0 additions & 2 deletions packages/types/src/Web3Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export interface Web3GasConfiguration {
* signer - optional - a Signer that sign the blockchain transactions. If a 'signer' is not provided, then 'contract' with an attached signer need to be used to make transactions
* provider - optional - a web3 provider. At least one of `signer`,`provider`, or `rpcUrl` is required
* rpcUrl - optinal - a JSON-RPC URL that can be used to connect to an ethereum network. At least one of `signer`, `provider`, or `rpcUrl` is required
* web3 - optional - Can use provider or web.currentProvider as a provider.
*
*/
export interface Web3SelfTransactionConfig extends Web3GasConfiguration {
Expand All @@ -50,7 +49,6 @@ export interface Web3SelfTransactionConfig extends Web3GasConfiguration {
privateKey?: string
provider?: Provider
rpcUrl?: string
web3?: any
chainId?: string | number

/** Function list with default gas configuration */
Expand Down
6 changes: 6 additions & 0 deletions packages/vda-token-client/.env.example
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"
11 changes: 11 additions & 0 deletions packages/vda-token-client/.gitignore
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/
4 changes: 4 additions & 0 deletions packages/vda-token-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2023-07-12 (v)
-------------------

- Initial release
78 changes: 78 additions & 0 deletions packages/vda-token-client/README.md
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);
```
23 changes: 23 additions & 0 deletions packages/vda-token-client/Test.md
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
```
43 changes: 43 additions & 0 deletions packages/vda-token-client/package.json
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"
}
}
Loading

0 comments on commit 955807c

Please sign in to comment.