start ERC721 withdraw
MODIFY
README.md
README.md
@@ -34,6 +34,9 @@ const matic = new Matic({
// Set rootchain contract. See below for more information
rootChainAddress: <root-contract-address>,
+ // Set withdraw-manager Address. See below for more information
+ withdrawManagerAddress: <withdraw-manager-address>,
+
// Set matic network's WETH address. See below for more information
maticWethAddress: <matic-weth-address>,

MODIFY
examples/node/config.js
examples/node/config.js
@@ -2,6 +2,7 @@ module.exports = {
MATIC_PROVIDER: 'http://68.183.166.5:8545/',
PARENT_PROVIDER: 'https://ropsten.infura.io/matic',
ROOTCHAIN_ADDRESS: '0xc76a925ca7fc8bc9fccf3e8fc4481b95c7b519d5',
+ WITHDRAWMANAGER_ADDRESS: '0xaac5836efaf18c2b0a8cdd35034876daf657535b',
SYNCER_URL: 'https://matic-syncer.api.matic.network/api/v1',
WATCHER_URL: 'https://ropsten-watcher.api.matic.network/api/v1',
MATICWETH_ADDRESS: '0xd27Ba7002CAa42C220F1Aa8aC8b9AD648E8301b0',

MODIFY
examples/node/withdraw.js
examples/node/withdraw.js
@@ -12,6 +12,7 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ withdrawManagerAddress: config.WITHDRAWMANAGER_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`

MODIFY
examples/node/withdraw721.js
examples/node/withdraw721.js
@@ -2,7 +2,7 @@ const Matic = require('../../lib/index').default
const config = require('./config')
const token = config.ERC721_MATIC // test token address
-const tokenId = '31' // tokenId
+const tokenId = '34' // tokenId
const from = config.FROM_ADDRESS // from address
// Create object of Matic
@@ -12,15 +12,16 @@ const matic = new Matic({
rootChainAddress: config.ROOTCHAIN_ADDRESS,
syncerUrl: config.SYNCER_URL,
watcherUrl: config.WATCHER_URL,
+ withdrawManagerAddress: config.WITHDRAWMANAGER_ADDRESS,
})
matic.wallet = config.PRIVATE_KEY // prefix with `0x`
var transactionHash =
- '0x517356669a8766de1efe9a065a2c8e05364f239b7a36bf2a7753c0a6f8e968f8'
+ '0xe7a17a9bf636d837c1b9ab493f3fe5808390062c2ff9bc310aae8d05aaa113cb'
matic
- .startWithdraw(token, tokenId, {
+ .startERC721Withdraw(token, tokenId, {
from,
onTransactionHash: txHash => {
transactionHash = txHash

MODIFY
src/index.js
src/index.js
@@ -20,6 +20,7 @@ import RootChainArtifacts from '../artifacts/RootChain'
import ChildERC20Artifacts from '../artifacts/ChildERC20'
import ChildERC721Artifacts from '../artifacts/ChildERC721'
import StandardTokenArtifacts from '../artifacts/StandardToken'
+import WithdrawManagerArtifacts from '../artifacts/WithdrawManager'
const rlp = utils.rlp
@@ -36,6 +37,7 @@ export default class Matic {
this._watcherUrl = options.watcherUrl
this._rootChainAddress = options.rootChainAddress
this._maticWethAddress = options.maticWethAddress
+ this._withdrawManagerAddress = options.withdrawManagerAddress
// create rootchain contract
this._rootChainContract = new this._parentWeb3.eth.Contract(
@@ -43,6 +45,12 @@ export default class Matic {
this._rootChainAddress
)
+ // create withdraw manager contract
+ this._withdrawManagerContract = new this._parentWeb3.eth.Contract(
+ WithdrawManagerArtifacts.abi,
+ this._withdrawManagerAddress
+ )
+
// internal cache
this._tokenCache = {}
this._tokenMappedCache = {}
@@ -288,6 +296,16 @@ export default class Matic {
return this._wrapWeb3Promise(withdrawTx.send(_options), options)
}
+ async startERC721Withdraw(token, tokenId, options = {}) {
+ if (options && (!options.from || !tokenId || !token)) {
+ throw new Error('Missing Parameters')
+ }
+ const _tokenContract = this._getERC721TokenContract(token, this._web3)
+ const withdrawTx = _tokenContract.methods.withdraw(tokenId)
+ const _options = await this._fillOptions(options, withdrawTx, this._web3)
+ return this._wrapWeb3Promise(withdrawTx.send(_options), options)
+ }
+
async getTx(txId) {
if (this._syncerUrl) {
try {

start ERC721 withdraw