update readme with respect to new code
MODIFY
examples/README.md
examples/README.md
-# Basic Nodejs example
+# Example
+
+This folder contains different example for different cases. All example are nodejs script, so can be easily run by `node` command.
+
+- plasma - plasma folder contains examples related to plasma api
+- pos - pos folder contains examples related to pos api
## How to use
+### 1. Set configuration
+
+Open `config.js` and set the keys like `privateKey`, `address` in user1, parent rpc etc.
+
+There are some prefilled data in `config.js` but feel free to change anything as per your needs.
+
+**Note:** - Be careful with your private key, Use a key you are comfortable with for development purpose. And try not to make it public by doing actions such as commiting to repo or referencing on any online site.
+
+### 2. Install package
+
+install related package by runing command -
-### SET ENV Variables
```
-export PRIVATE_KEY=<paste your private key here> // A sample private key prefix with `0x`
-export FROM=<paste address belonging to private key here> // Your address
+npm i
```
-Be careful with your private key, Use a key your are comfortable with for development purpose.
+**Note:-** Make sure you are inside examples folder.
-### Install and run:
+### 3. Run script
-```bash
-cd .. // make sure you are on matic.js directory
-npm run build && node examples/balance-of-ERC20.js
+run any example script by using
+
+```
+node <file_path>
+```
+
+let's run a plasma erc20 balance example
+
+```
+node plasma/erc20/balance.js
+```

DELETE
examples/execute-order.js
-const utils = require('./utils')
-
-// it is not recommended to hard-code private keys in the script, this is only for testing.
-// prefix private keys with '0x'
-const privateKey1 = '0x...' // owner of token1 (order creator)
-const privateKey2 = '0x...' // transaction executor; token owner approves this account to execute the transfer
-
-async function init() {
- const { matic, wallet, parent } = await utils.getMaticClient('testnet', 'v3')
-
- const token1 = '0x5696F5617ff401B8B1936EcFB57dA89CE0f054fF' // address of token to sell. Provided is a sample erc20 token deployed on testnetv3, with a public `mint` function - for testing
- const value1 = 1 // amount/token id of token 1 to sell. Please make sure the account holds the specified value
- matic.setWallet(privateKey1) // owner of token1 (order creator)
-
- const token2 = '0x63D052Dd8368F360dD5fFAeE08e5294CF4f33bCE' // address of token to buy. Provided is a sample erc721 token deployed on testnetv3, with a public `mint` function - for testing. Please make sure the token is not already minted before minting a new token
- const value2 = 2 // amount/token id of token 2 to sell.
-
- matic.setWallet(privateKey2) // transaction executor; token owner approves this account to execute the transfer
-
- const tokenOwner = wallet[1].address
- const spender = wallet[0].address // tx executor
-
- const orderFiller = wallet[0].address // address of account to transfer tokens to.
- const orderId = parent.utils.randomHex(32) // order Id is supposed to be unique for each order; a random 32 byte Hex string
- // console.log(orderId)
-
- const expire = 0 // block number to expire the tx at; 0 for no expiry
-
- // sell order
- let toSell = {
- token: token2,
- amount: value2,
- expiry: expire,
- orderId: orderId,
- spender: spender,
- }
-
- // buy order
- let toBuy = {
- token: token1,
- amount: value1,
- }
-
- const sig = await matic.getTransferSignature(toSell, toBuy, {
- from: tokenOwner,
- })
-
- console.log('signature', sig)
-
- // transfers `toSell.token` from `tokenOwner` to `orderFiller`
- const tx = await matic.transferWithSignature(
- sig, // signature with the intent to buy tokens
- toSell, // sell order
- toBuy, // buy order
- orderFiller, // order fulfiller
- {
- from: spender, // approved spender
- }
- )
-
- console.log('tx', tx.transactionHash)
-}
-
-init()

update readme with respect to new code