add safeTransferFrom method for ERC721 deposit
ADD
examples/node/safeTransferFrom.js
+const Matic = require('maticjs').default
+const config = require('./config')
+
+const token = config.ROPSTEN_ERC721_TOKEN // test token address
+const tokenId = '74' // 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,
+})
+
+matic.wallet = config.PRIVATE_KEY // prefix with `0x`
+
+matic.safeTransferFrom(token, tokenId, {
+ from,
+ onTransactionHash: (hash) => {
+ // action on Transaction success
+ console.log(hash) // eslint-disable-line
+ },
+})

MODIFY
src/index.js
src/index.js
@@ -175,6 +175,28 @@ export default class Matic {
return this._wrapWeb3Promise(depositTx.send(_options), options)
}
+
+ async safeTransferFrom(token, tokenId, options = {}) {
+ if (options && (!options.from || !tokenId || !token)) {
+ throw new Error('Missing Parameters')
+ }
+
+ const _tokenContract = this._getERC721TokenContract(token, this._parentWeb3)
+
+ const safeTransferFromTx = await _tokenContract.methods.safeTransferFrom(
+ options.from,
+ this._rootChainAddress,
+ tokenId
+ )
+ const _options = await this._fillOptions(
+ options,
+ safeTransferFromTx,
+ this._parentWeb3
+ )
+
+ return this._wrapWeb3Promise(safeTransferFromTx.send(_options), options)
+ }
+
async approveERC721TokenForDeposit(token, tokenId, options = {}) {
if (options && (!options.from || !tokenId || !token)) {
throw new Error('Missing Parameters')

add safeTransferFrom method for ERC721 deposit