approve and deposit ERC721
MODIFY
examples/node/config.js
examples/node/config.js
@@ -10,6 +10,8 @@ module.exports = {
PRIVATE_KEY:
'0x03599966360596FFC19F0E3E98371BD115910107016D90D5E8427B661ECA47A0',
FROM_ADDRESS: '0xdea6D214E7505391FD64405fE8fbA206C2073Ee4',
- TEST_TOKEN: '0xba3204eb2d2b3d9c2071BA9310d7155B2ED1Fd63',
- KOVAN_TEST: '0x48d35e70b279927ec4869c0679900a726ef1728e',
+ MATIC_TOKEN: '0xba3204eb2d2b3d9c2071BA9310d7155B2ED1Fd63',
+ TEST_TOKEN: '0x48d35e70b279927ec4869c0679900a726ef1728e',
+ ERC721_TOKEN:'0xfeb14bc6aaf5d39fa43ff51ed94e6c260539e296',
+ ERC721_MATIC:'0xAF853C5A24f2CDF9666EfC583dE2DaA9c91F1529',
}
\ No newline at end of file

ADD
examples/node/deposit721.js
+const Matic = require('../../lib/index').default
+const config = require('./config')
+
+const token = config.ERC721_TOKEN // test token address
+const tokenId = '34' // amount in wei
+const from = config.FROM_ADDRESS // from address
+
+// 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,
+})
+
+matic.wallet = config.PRIVATE_KEY // prefix with `0x`
+
+matic
+ .approveERC721TokenForDeposit(token, tokenId, {
+ from,
+ onTransactionHash: () => {
+ // action on Transaction success
+ },
+ })
+ .then(() => {
+ matic.depositERC721Tokens(token, from, tokenId, {
+ from,
+ onTransactionHash: () => {
+ // action on Transaction success
+ },
+ })
+ })

MODIFY
src/index.js
src/index.js
@@ -21,7 +21,6 @@ import ChildERC20Artifacts from '../artifacts/ChildERC20'
import ChildERC721Artifacts from '../artifacts/ChildERC721'
import StandardTokenArtifacts from '../artifacts/StandardToken'
import WithdrawManagerArtifacts from '../artifacts/WithdrawManager'
-import DepositManagerArtifacts from '../artifacts/DepositManager'
const rlp = utils.rlp
@@ -39,7 +38,6 @@ export default class Matic {
this._rootChainAddress = options.rootChainAddress
this._maticWethAddress = options.maticWethAddress
this._withdrawManagerAddress = options.withdrawManagerAddress
- this._depositManagerAddress = options.depositManagerAddress
// create rootchain contract
this._rootChainContract = new this._parentWeb3.eth.Contract(
@@ -53,12 +51,6 @@ export default class Matic {
this._withdrawManagerAddress
)
- // create deposit manager contract
- this._depositManagerContract = new this._parentWeb3.eth.Contract(
- DepositManagerArtifacts.abi,
- this._depositManagerAddress
- )
-
// internal cache
this._tokenCache = {}
this._tokenMappedCache = {}
@@ -113,6 +105,24 @@ export default class Matic {
return this._tokenMappedCache[_a]
}
+ async balanceOfERC721(address, token, options={}) {
+ let web3Object = this._web3
+ if (options.parent) {
+ web3Object = this._parentWeb3
+ }
+ const balance = this._getERC721TokenContract(token,web3Object).methods.balanceOf(address).call()
+ return balance
+ }
+
+ async tokenOfOwnerByIndex(index, owner, token,options={}) {
+ let web3Object = this._web3
+ if (options.parent) {
+ web3Object = this._parentWeb3
+ }
+ const tokenId = this._getERC721TokenContract(token,web3Object).methods.tokenOfOwnerByIndex(owner, index).call()
+ return tokenId
+ }
+
async depositEthers(user, options = {}) {
if (options && (!options.from || !user || !options.value)) {
throw new Error('Missing Parameters')
@@ -166,6 +176,26 @@ export default class Matic {
return this._wrapWeb3Promise(depositTx.send(_options), options)
}
+ async approveERC721TokenForDeposit(token, tokenId, options = {}) {
+ if (options && (!options.from || !tokenId || !token)) {
+ throw new Error('Missing Parameters')
+ }
+
+ const _tokenContract = this._getERC721TokenContract(token, this._parentWeb3)
+
+ const approveTx = await _tokenContract.methods.approve(
+ this._rootChainAddress,
+ tokenId
+ )
+ const _options = await this._fillOptions(
+ options,
+ approveTx,
+ this._parentWeb3
+ )
+
+ return this._wrapWeb3Promise(approveTx.send(_options), options)
+ }
+
async depositERC721Tokens(token, user, tokenId, options = {}) {
if (options && (!options.from || !token || !user || !tokenId)) {
throw new Error('Missing Parameters')

approve and deposit ERC721