confirm withdraw erc721
MODIFY
README.md
README.md
@@ -115,6 +115,11 @@ await matic.withdraw(
options // transaction fields
)
+await matic.confirmWithdrawERC721(
+ txId, // Transaction id generated from the 'startWithdraw' method
+ options // transaction fields
+)
+
```
### How it works?
@@ -155,6 +160,7 @@ Please write to info@matic.network to request TEST tokens for development purpos
- <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>
+- <a href="#confirmWithdrawERC721"><code>matic.<b>confirmWithdrawERC721()</b></code></a>
---
<a name="initialize"></a>
@@ -385,6 +391,27 @@ matic.withdraw("0xabcd...789", {
})
```
+---
+
+<a name="confirmWithdrawERC721"></a>
+
+#### matic.confirmWithdrawERC721(txId, options)
+
+Withdraw tokens on mainchain using `txId` from `startWithdraw` method after header has been submitted to mainchain.
+
+- `txId` must be valid tx hash
+- `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.confirmWithdrawERC721("0xabcd...789", {
+ from: "0xABc578455..."
+})
+```
+
### Support
Please write to info@matic.network for integration support. If you have any queries, feedback or feature requests, feel free to reach out to us on telegram: [t.me/maticnetwork](https://t.me/maticnetwork)

MODIFY
examples/node/config.js
examples/node/config.js
@@ -15,5 +15,5 @@ module.exports = {
ROPSTEN_TEST_TOKEN: '0x28C8713DDe7F063Fdc4cA01aB2A8856e0F243Fec', // Contract for ERC20 in Ropsten
MATIC_TEST_TOKEN: '0x9a93c912F4eFf0254d178a18ACD980C1B05b57b0', // Contract for ERC20 in Matic testnet
ROPSTEN_ERC721_TOKEN: '0x07d799252cf13c01f602779b4dce24f4e5b08bbd', // Contract for ERC721 in Ropsten testnet
- MATIC_ERC721_TOKEN: '0x9f289a264b6db56d69ad53f363d06326b984e637', // Contract for ERC721 in matic testnet
+ MATIC_ERC721_TOKEN: '0x8D5231e0B79edD9331e0CF0d4B9f3F30d05C47A5', // Contract for ERC721 in matic testnet
}
\ No newline at end of file

RENAME
examples/node/confirm-withdraw.js
examples/node/confirm-withdraw-ERC20.js
@@ -4,7 +4,6 @@ const config = require('./config')
const from = config.FROM_ADDRESS // from address
-// 0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5 ERC721 withdraw
var transactionHash = '0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5' // Insert txHash generated from initiate-withdraw.js
// Create object of Matic
@@ -23,7 +22,6 @@ matic.initialize().then(() => {
from,
}).then((res) => {
console.log(res) // eslint-disable-line
-
})
})
//Wait for 5 mins till the checkpoint is submitted, then run the confirm withdraw

ADD
examples/node/confirm-withdraw-ERC721.js
+const Matic = require('@maticnetwork/maticjs').default
+
+const config = require('./config')
+
+const from = config.FROM_ADDRESS // from address
+
+// 0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5 ERC721 withdraw
+var transactionHash = '0xbbaf7712bc426b665650992215f9c15ac9bda72bbb4e7d453ba9ed3875e0ebf5' // Insert txHash generated from initiate-withdraw.js
+
+// Create object of Matic
+const matic = new Matic({
+ maticProvider: config.MATIC_PROVIDER,
+ parentProvider: config.PARENT_PROVIDER,
+ rootChain: config.ROOTCHAIN_ADDRESS,
+ registry: config.REGISTRY_ADDRESS,
+ depositManager: config.DEPOSITMANAGER_ADDRESS,
+ withdrawManager: config.WITHDRAWMANAGER_ADDRESS,
+})
+
+matic.initialize().then(() => {
+ matic.setWallet(config.PRIVATE_KEY)
+ matic.confirmWithdrawERC721(transactionHash, {
+ from,
+ }).then((res) => {
+ console.log(res) // eslint-disable-line
+ // 0xebece1474592c1556b3389a1a76908b9bdfd4118e1d3f2e9308d6f1c5f173dd4
+ })
+})
+//Wait for 5 mins till the checkpoint is submitted, then run the confirm withdraw

MODIFY
src/index.ts
src/index.ts
@@ -175,4 +175,8 @@ export default class Matic extends ContractsBase {
withdraw(txHash: string, options?: SendOptions) {
return this.withdrawManager.startExitWithBurntERC20Tokens(txHash, options)
}
+
+ confirmWithdrawERC721(txHash: string, options?: SendOptions) {
+ return this.withdrawManager.startExitWithBurntERC721Tokens(txHash, options)
+ }
}

MODIFY
src/root/WithdrawManager.ts
src/root/WithdrawManager.ts
@@ -133,9 +133,28 @@ export default class WithdrawManager extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
- async startExitForMintWithTokenURITokens(burnERC20TxHash, options?) {
+ async startExitWithBurntERC721Tokens(burnTxHash, options?) {
+ const payload = await this._buildPayloadForExit(burnTxHash)
+ const txObject = this.erc721Predicate.methods.startExitWithBurntTokens(
+ payload,
+ )
+
+ const _options = await this._fillOptions(
+ options,
+ txObject,
+ this.web3Client.getParentWeb3(),
+ )
+
+ if (options.encodeAbi) {
+ _options.data = txObject.encodeABI()
+ return _options
+ }
+ return this.web3Client.send(txObject, _options)
+ }
+
+ async startExitForMintWithTokenURITokens(burnTxHash, options?) {
const { payload, mint } = await this._startExitForMintWithTokenURITokens(
- burnERC20TxHash,
+ burnTxHash,
)
return this.web3Client.send(
this.erc721Predicate.methods.startExitForMintWithTokenURITokens(
@@ -192,15 +211,15 @@ export default class WithdrawManager extends ContractsBase {
return { payload, mint }
}
- private async _buildPayloadForExit(burnERC20TxHash) {
+ private async _buildPayloadForExit(burnTxHash) {
// check checkpoint
const lastChildBlock = await this.rootChain.getLastChildBlock()
const burnTx = await this.web3Client
.getMaticWeb3()
- .eth.getTransaction(burnERC20TxHash)
+ .eth.getTransaction(burnTxHash)
const receipt = await this.web3Client
.getMaticWeb3()
- .eth.getTransactionReceipt(burnERC20TxHash)
+ .eth.getTransactionReceipt(burnTxHash)
const block: any = await this.web3Client
.getMaticWeb3()
.eth.getBlock(burnTx.blockNumber, true /* returnTransactionObjects */)

confirm withdraw erc721