dev: add comments in example
MODIFY
examples/execute-order.js
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.
-const privateKey1 = '0x..'
-const privateKey2 = '0x..'
+// 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 } = await utils.getMaticClient('testnet', 'v3')
+ const { matic, wallet, parent } = await utils.getMaticClient('testnet', 'v3')
- const token1 = '0x683E640bb210355B877eae20ae083971eF3BFDbD' // 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
+ 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 = '0x37fc65a422fdCc3BBC8Fa27f32035Bea9aCCA438' // 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 = '12' // amount/token id of token 2 to sell.
+ 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[0].address
- const spender = wallet[1].address // tx executor
+ const tokenOwner = wallet[1].address
+ const spender = wallet[0].address // tx executor
- const orderFiller = '0x..' // address of account to transfer tokens to. Address corresponding to privateKey2
+ 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 orderId = '' // order Id is supposed to be unique for each order; a random 32 byte Hex string
const expire = 0 // block number to expire the tx at; 0 for no expiry
// sell order
let toSell = {
- token: token1,
- amount: value1,
+ token: token2,
+ amount: value2,
expiry: expire,
orderId: orderId,
spender: spender,
@@ -35,8 +37,8 @@ async function init() {
// buy order
let toBuy = {
- token: token2,
- amount: value2,
+ token: token1,
+ amount: value1,
}
const sig = await matic.getTransferSignature(toSell, toBuy, {
@@ -56,7 +58,7 @@ async function init() {
}
)
- console.log('tx', tx)
+ console.log('tx', tx.transactionHash)
}
init()

MODIFY
examples/utils.js
examples/utils.js
@@ -17,7 +17,8 @@ async function getMaticClient(_network, _version) {
})
await matic.initialize()
const wallet = matic.web3Client.getWallet()
- return { matic, network, wallet }
+ const parent = matic.web3Client.getParentWeb3()
+ return { matic, network, wallet, parent }
}
function getPrivateKey() {

dev: add comments in example