Safe deposit erc721
MODIFY
examples/node/safeDepositERC721Tokens.js
examples/node/safeDepositERC721Tokens.js
-const Matic = require('maticjs').default
+const Matic = require('../../dist/index').default
const config = require('./config')
const token = config.ROPSTEN_ERC721_TOKEN // test token address
-const tokenId = '72' // ERC721 token Id
+const tokenId = '1734' // ERC721 token Id
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,
+ 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.wallet = config.PRIVATE_KEY // prefix with `0x`sla
+matic.initialize().then(() => {
matic.safeDepositERC721Tokens(token, tokenId, {
from,
- onTransactionHash: (hash) => {
- // action on Transaction success
- console.log(hash) // eslint-disable-line
- },
+ }).then((receipt) => {
+ // Deposit tokens
+ console.log('receipt', receipt) // eslint-disable-line
+ })
+
})
\ No newline at end of file

MODIFY
src/index.ts
src/index.ts
@@ -102,6 +102,30 @@ export default class Matic extends ContractsBase {
return this.depositManager.depositERC20ForUser(token, amount, user, options)
}
+ async safeDepositERC721Tokens(token: address, tokenId: string, options?: SendOptions) {
+ if (options && (!options.from || !tokenId || !token)) {
+ throw new Error('options.from, token or tokenId is missing')
+ }
+ const txObject = this.getERC721TokenContract(
+ token,
+ options.parent,
+ ).methods.safeTransferFrom(options.from, this.depositManager.getAddress(), tokenId)
+
+ const _options = await this._fillOptions(
+ options,
+ txObject,
+ this.web3Client.getParentWeb3()
+ )
+
+ if (options.encodeAbi) {
+ _options.data = txObject.encodeABI()
+ _options.to = token
+ return _options
+ }
+
+ return this.web3Client.send(txObject, _options)
+ }
+
startWithdraw(token: address, amount: BN | string, options?: SendOptions) {
if (options && (!options.from || !amount || !token)) {
throw new Error(`options.from, amount or token is missing`)

Safe deposit erc721