start withdraw erc721
MODIFY
README.md
README.md
@@ -101,6 +101,13 @@ await matic.startWithdraw(
options // transaction fields
)
+// Initiate withdrawal of ERC721 from Matic and retrieve the Transaction id
+await matic.startWithdrawERC721(
+ token, // Token address
+ tokenId, // TokenId for withdraw
+ options // transaction fields
+)
+
// Withdraw funds from the Matic chain using the Transaction id generated from the 'startWithdraw' method
// after header has been submitted to mainchain
await matic.withdraw(
@@ -146,6 +153,7 @@ Please write to info@matic.network to request TEST tokens for development purpos
- <a href="#transferERC20Tokens"><code>matic.<b>transferERC20Tokens()</b></code></a>
- <a href="#transferERC721Tokens"><code>matic.<b>transferERC721Tokens()</b></code></a>
- <a href="#startWithdraw"><code>matic.<b>startWithdraw()</b></code></a>
+- <a href="#startWithdrawERC721"><code>matic.<b>startWithdrawERC721()</b></code></a>
- <a href="#withdraw"><code>matic.<b>withdraw()</b></code></a>
---
@@ -335,6 +343,29 @@ matic
---
+<a name="startWithdrawERC721"></a>
+
+#### matic.startWithdrawERC721(token, tokenId, options)
+
+Start withdraw process with given `tokenId` for `token`.
+
+- `token` must be valid ERC721 token address
+- `tokenId` must be token tokenId (string, not in Number)
+- `options` see [more infomation here](#approveERC20TokensForDeposit)
+
+This returns `Promise` object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
+
+Example:
+
+```js
+matic
+ .startWithdrawERC721("0x718Ca123...", "1000000000000000000", {
+ from: "0xABc578455..."
+ })
+```
+
+---
+
<a name="withdraw"></a>
#### matic.withdraw(txId, options)

MODIFY
examples/node/initiate-withdraw-ERC20.js
examples/node/initiate-withdraw-ERC20.js
const bn = require('bn.js')
-const Matic = require('@maticnetwork/maticjs').default
+const Matic = require('../../dist/index').default
const config = require('./config')

MODIFY
examples/node/initiate-withdraw-ERC721.js
examples/node/initiate-withdraw-ERC721.js
-const Matic = require('maticjs').default
+const Matic = require('../../dist/index').default
+
const config = require('./config')
const token = config.MATIC_ERC721_TOKEN // test token address
-const tokenId = '1' // ERC721 token Id
+const tokenId = 1963 // tokenId
+
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,
- withdrawManagerAddress: config.WITHDRAWMANAGER_ADDRESS,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ registry: config.REGISTRY_ADDRESS,
+ depositManager: config.DEPOSITMANAGER_ADDRESS,
+ withdrawManager: config.WITHDRAWMANAGER_ADDRESS,
})
-matic.wallet = config.PRIVATE_KEY // prefix with `0x`
-
+matic.initialize().then(() => {
+ matic.setWallet(config.PRIVATE_KEY)
matic
- .startERC721Withdraw(token, tokenId, {
+ .startWithdrawERC721(token, tokenId, {
from,
- onTransactionHash: (hash) => {
- // action on Transaction success
- console.log(hash) // eslint-disable-line
- },
+ }).then((res) => {
+ console.log(res) // eslint-disable-line
})
-// NOTE: Wait for next checkpoint, which will take approximately 5-10 mins.
-// Then you can call complete-withdraw.js to submit proof.
+})
\ No newline at end of file

MODIFY
src/index.ts
src/index.ts
@@ -165,6 +165,13 @@ export default class Matic extends ContractsBase {
return this.withdrawManager.burnERC20Tokens(token, amount, options)
}
+ startWithdrawERC721(token: address, tokenId: string, options?: SendOptions) {
+ if (options && (!options.from || !tokenId || !token)) {
+ throw new Error(`options.from, tokenId or token is missing`)
+ }
+ return this.withdrawManager.burnERC721Token(token, tokenId, options)
+ }
+
withdraw(txHash: string, options?: SendOptions) {
return this.withdrawManager.startExitWithBurntERC20Tokens(txHash, options)
}

MODIFY
src/root/WithdrawManager.ts
src/root/WithdrawManager.ts
@@ -80,13 +80,24 @@ export default class WithdrawManager extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- burnERC721Token(token: address, tokenId: BN | string, options?: SendOptions) {
- return this.wrapWeb3Promise(
- this.getERC721TokenContract(token)
- .methods.withdraw(this.encode(tokenId))
- .send(options),
+ async burnERC721Token(token: address, tokenId: string, options?: SendOptions) {
+ const txObject = this.getERC721TokenContract(token).methods.withdraw(
+ tokenId
+ )
+
+ const _options = await this._fillOptions(
options,
+ txObject,
+ this.web3Client.getMaticWeb3(),
)
+
+ if (options.encodeAbi) {
+ _options.data = txObject.encodeABI()
+ _options.to = token
+ return _options
+ }
+
+ return this.web3Client.send(txObject, _options)
}
processExits(token: address, options?: SendOptions) {

start withdraw erc721