added get token of owner by index
MODIFY
artifacts/ChildERC721.json
artifacts/ChildERC721.json
"stateMutability": "view",
"type": "function"
},
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "sig",
+ "type": "bytes"
+ },
+ {
+ "name": "tokenId",
+ "type": "uint256"
+ },
+ {
+ "name": "data",
+ "type": "bytes32"
+ },
+ {
+ "name": "expiration",
+ "type": "uint256"
+ },
+ {
+ "name": "to",
+ "type": "address"
+ }
+ ],
+ "name": "transferWithSig",
+ "outputs": [
+ {
+ "name": "",
+ "type": "address"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "from",
+ "type": "address"
+ },
+ {
+ "name": "to",
+ "type": "address"
+ },
+ {
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "transferFrom",
+ "outputs": [],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "withdraw",
+ "outputs": [],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
{
"constant": true,
"inputs": [
"stateMutability": "nonpayable",
"type": "function"
},
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "user",
+ "type": "address"
+ },
+ {
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "deposit",
+ "outputs": [],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
{
"constant": true,
"inputs": [
"stateMutability": "view",
"type": "function"
},
+ {
+ "constant": false,
+ "inputs": [
+ {
+ "name": "tokenId",
+ "type": "uint256"
+ }
+ ],
+ "name": "mint",
+ "outputs": [],
+ "payable": false,
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
{
"constant": false,
"inputs": [
"stateMutability": "nonpayable",
"type": "function"
},
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "EIP712_TOKEN_TRANSFER_ORDER_SCHEMA_HASH",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bytes32"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "",
+ "type": "bytes32"
+ }
+ ],
+ "name": "disabledHashes",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bool"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [
+ {
+ "name": "spender",
+ "type": "address"
+ },
+ {
+ "name": "tokenIdOrAmount",
+ "type": "uint256"
+ },
+ {
+ "name": "data",
+ "type": "bytes32"
+ },
+ {
+ "name": "expiration",
+ "type": "uint256"
+ }
+ ],
+ "name": "getTokenTransferOrderHash",
+ "outputs": [
+ {
+ "name": "orderHash",
+ "type": "bytes32"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
{
"constant": false,
"inputs": [
"stateMutability": "view",
"type": "function"
},
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "EIP712_DOMAIN_HASH",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bytes32"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "constant": true,
+ "inputs": [],
+ "name": "EIP712_DOMAIN_SCHEMA_HASH",
+ "outputs": [
+ {
+ "name": "",
+ "type": "bytes32"
+ }
+ ],
+ "payable": false,
+ "stateMutability": "view",
+ "type": "function"
+ },
{
"constant": true,
"inputs": [
{
"name": "_token",
"type": "address"
- },
- {
- "name": "name",
- "type": "string"
- },
- {
- "name": "symbol",
- "type": "string"
}
],
"payable": false,
"name": "from",
"type": "address"
},
- {
- "indexed": true,
- "name": "to",
- "type": "address"
- },
{
"indexed": false,
"name": "amountOrTokenId",
"type": "uint256"
- }
- ],
- "name": "LogTransfer",
- "type": "event"
- },
- {
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "name": "from",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "to",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "tokenId",
- "type": "uint256"
- }
- ],
- "name": "Transfer",
- "type": "event"
},
{
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "name": "owner",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "approved",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "tokenId",
+ "indexed": false,
+ "name": "input1",
"type": "uint256"
- }
- ],
- "name": "Approval",
- "type": "event"
- },
- {
- "anonymous": false,
- "inputs": [
- {
- "indexed": true,
- "name": "owner",
- "type": "address"
- },
- {
- "indexed": true,
- "name": "operator",
- "type": "address"
},
{
"indexed": false,
- "name": "approved",
- "type": "bool"
+ "name": "output1",
+ "type": "uint256"
}
],
- "name": "ApprovalForAll",
+ "name": "Deposit",
"type": "event"
},
{
"type": "uint256"
}
],
- "name": "Deposit",
+ "name": "Withdraw",
"type": "event"
},
{
"type": "address"
},
{
- "indexed": false,
- "name": "amountOrTokenId",
- "type": "uint256"
- },
- {
- "indexed": false,
- "name": "input1",
- "type": "uint256"
+ "indexed": true,
+ "name": "to",
+ "type": "address"
},
{
"indexed": false,
- "name": "output1",
+ "name": "amountOrTokenId",
"type": "uint256"
}
],
- "name": "Withdraw",
+ "name": "LogTransfer",
"type": "event"
},
{
"type": "event"
},
{
- "constant": false,
+ "anonymous": false,
"inputs": [
{
- "name": "user",
+ "indexed": true,
+ "name": "from",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "to",
"type": "address"
},
{
+ "indexed": true,
"name": "tokenId",
"type": "uint256"
}
],
- "name": "deposit",
- "outputs": [],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
+ "name": "Transfer",
+ "type": "event"
},
{
- "constant": false,
+ "anonymous": false,
"inputs": [
{
+ "indexed": true,
+ "name": "owner",
+ "type": "address"
+ },
+ {
+ "indexed": true,
+ "name": "approved",
+ "type": "address"
+ },
+ {
+ "indexed": true,
"name": "tokenId",
"type": "uint256"
}
],
- "name": "withdraw",
- "outputs": [],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
+ "name": "Approval",
+ "type": "event"
},
{
- "constant": false,
+ "anonymous": false,
"inputs": [
{
- "name": "from",
+ "indexed": true,
+ "name": "owner",
"type": "address"
},
{
- "name": "to",
+ "indexed": true,
+ "name": "operator",
"type": "address"
},
{
- "name": "tokenId",
- "type": "uint256"
+ "indexed": false,
+ "name": "approved",
+ "type": "bool"
}
],
- "name": "transferFrom",
- "outputs": [],
- "payable": false,
- "stateMutability": "nonpayable",
- "type": "function"
+ "name": "ApprovalForAll",
+ "type": "event"
}
]
}

ADD
examples/node/token-of-owner-ERC721.js
+const Matic = require('maticjs').default
+const config = require('./config')
+
+// Create object of Matic
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChainAddress: config.ROOTCHAIN_ADDRESS,
+ syncerUrl: config.SYNCER_URL,
+ watcherUrl: config.WATCHER_URL,
+ maticWethAddress: config.MATICWETH_ADDRESS,
+})
+matic.wallet = config.PRIVATE_KEY // prefix with `0x`
+
+const tokenAddress = config.ROPSTEN_ERC721_TOKEN // token address on mainchain
+const from = config.FROM_ADDRESS // from address
+
+matic
+ .tokenOfOwnerByIndexERC721(from, tokenAddress, 0, {
+ from,
+ parent: true, // For transaction on Main network (false for Matic Network)
+ })
+ .then(hash => {
+ // action on Transaction success
+ console.log(hash) // eslint-disable-line
+ })

MODIFY
src/index.js
src/index.js
@@ -118,10 +118,23 @@ export default class Matic {
if (options.parent) {
web3Object = this._parentWeb3
}
- const balance = await this._getERC721TokenContract(token,web3Object).methods.balanceOf(address).call()
+ const balance = await this._getERC721TokenContract(token, web3Object)
+ .methods.balanceOf(address)
+ .call()
return balance
}
+ async tokenOfOwnerByIndexERC721(address, token, index, options = {}) {
+ let web3Object = this._web3
+ if (options.parent) {
+ web3Object = this._parentWeb3
+ }
+ const tokenID = await this._getERC721TokenContract(token, web3Object)
+ .methods.tokenOfOwnerByIndex(address, index)
+ .call()
+ return tokenID
+ }
+
async depositEthers(options = {}) {
if (options && (!options.from || !options.value)) {
throw new Error('Missing Parameters')
@@ -180,7 +193,10 @@ export default class Matic {
throw new Error('Missing Parameters')
}
- const _tokenContract = this._getERC721TokenContract(token, this._parentWeb3)
+ const _tokenContract = this._getERC721TokenContract(
+ token,
+ this._parentWeb3
+ )
const approveTx = await _tokenContract.methods.approve(
this._rootChainAddress,
@@ -250,12 +266,7 @@ export default class Matic {
// if matic chain, transfer normal WETH tokens
if (!options.parent) {
- return this.transferTokens(
- this._maticWethAddress,
- to,
- amount,
- options
- )
+ return this.transferTokens(this._maticWethAddress, to, amount, options)
}
const gasLimit = await this._parentWeb3.eth.estimateGas({
@@ -425,14 +436,15 @@ export default class Matic {
}
async processExits(rootTokenAddress, options = {}) {
- const processExits = this._withdrawManagerContract.methods.processExits(rootTokenAddress)
+ const processExits = this._withdrawManagerContract.methods.processExits(
+ rootTokenAddress
+ )
const _options = await this._fillOptions(
options,
processExits,
this._parentWeb3
)
return this._wrapWeb3Promise(processExits.send(_options), options)
-
}
async withdrawLocally(txId, options = {}) {
@@ -547,7 +559,11 @@ export default class Matic {
? await txObject.estimateGas({ from, value: options.value })
: options.gasLimit || options.gas,
// NOTE: Gas Price is set to '0', take care of type of gasPrice on web3^1.0.0-beta.36
- !options.gasPrice ? !web3.matic ? await web3.eth.getGasPrice() : '0' : options.gasPrice,
+ !options.gasPrice
+ ? !web3.matic
+ ? await web3.eth.getGasPrice()
+ : '0'
+ : options.gasPrice,
!options.nonce
? await web3.eth.getTransactionCount(from, 'pending')
: options.nonce,

added get token of owner by index