transfer erc721 tokens
MODIFY
README.md
README.md
@@ -86,6 +86,14 @@ await matic.transferERC20Tokens(
options // transaction fields
)
+// Transfer ERC721 token on Matic
+await matic.transferERC721Tokens(
+ token, // Token address
+ user, // Recipient address
+ tokenId, // TokenId
+ options // transaction fields
+)
+
// Initiate withdrawal of ERC20 from Matic and retrieve the Transaction id
await matic.startWithdraw(
token, // Token address
@@ -136,6 +144,7 @@ Please write to info@matic.network to request TEST tokens for development purpos
- <a href="#depositERC20ForUser"><code>matic.<b>depositERC20ForUser()</b></code></a>
- <a href="#safeDepositERC721Tokens"><code>matic.<b>safeDepositERC721Tokens()</b></code></a>
- <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="#withdraw"><code>matic.<b>withdraw()</b></code></a>
---
@@ -274,6 +283,35 @@ matic.transferERC20Tokens('0x718Ca123...', user, '1000000000000000000', {
---
+<a name="transferERC721Tokens"></a>
+
+#### matic.transferERC721Tokens(token, user, tokenId, options)
+
+Transfer given `tokenId` of `token` to `user`.
+
+- `token` must be valid ERC721 token address
+- `user` must be value account address
+- `tokenId` must be token amount in wei (string, not in Number)
+- `options` see [more infomation here](#approveERC20TokensForDeposit)
+ - `parent` must be boolean value. For token transfer on Main chain, use `parent: true`
+
+This returns `Promise` object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
+
+Example:
+
+```js
+const user = <your-address> or <any-account-address>
+
+matic.transferERC721Tokens('0x718Ca123...', user, '100006500000000000000', {
+ from: '0xABc578455...',
+
+ // For token transfer on Main network
+ // parent: true
+})
+```
+
+---
+
<a name="startWithdraw"></a>
#### matic.startWithdraw(token, amount, options)

MODIFY
examples/node/safeDepositERC721Tokens.js
examples/node/safeDepositERC721Tokens.js
@@ -5,7 +5,6 @@ const token = config.ROPSTEN_ERC721_TOKEN // test token address
const from = config.FROM_ADDRESS // from address
const tokenId = 1963
-
// Create object of Matic
const matic = new Matic({
maticProvider: config.MATIC_PROVIDER,

MODIFY
examples/node/transfer-ERC721.js
examples/node/transfer-ERC721.js
-const Matic = require('maticjs').default
+const Matic = require('../../dist/index').default
+
const config = require('./config')
const from = config.FROM_ADDRESS // from address
-const receipent = 'Paste Your receipent address here ...' // receipent address
+const recipient = '0x9fB29AAc15b9A4B7F17c3385939b007540f4d791' // receipent address
const token = config.MATIC_ERC721_TOKEN // test token address
-const tokenId = '1' // ERC721 token Id
+const tokenId = 1963
// 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`
-
-// Send Tokens
-matic.transferERC721Tokens(token, receipent, tokenId, {
+matic.initialize().then(() => {
+ matic.setWallet(config.PRIVATE_KEY)
+ matic.transferERC721Tokens(token, recipient, tokenId, {
from,
+ // encodeAbi: true,
// parent: true, // For token transfer on Main network (false for Matic Network)
- onTransactionHash: (hash) => {
- // action on Transaction success
- console.log(hash) // eslint-disable-line
- },
+ }).then((res)=>{
+ console.log("hash", res) // eslint-disable-line
})
+})
+

MODIFY
src/index.ts
src/index.ts
@@ -78,6 +78,38 @@ export default class Matic extends ContractsBase {
return this.web3Client.send(txObject, _options)
}
+ async transferERC721Tokens(
+ token: address,
+ to: address,
+ tokenId: string,
+ options?: SendOptions,
+ ) {
+ if (options && (!options.from || !tokenId || !token || !to)) {
+ throw new Error('options.from, to, token or tokenId is missing')
+ }
+
+ const txObject = this.getERC721TokenContract(
+ token,
+ options.parent,
+ ).methods.transferFrom(options.from, to, tokenId)
+
+ const _options = await this._fillOptions(
+ options,
+ txObject,
+ options.parent
+ ? this.web3Client.getParentWeb3()
+ : this.web3Client.getMaticWeb3(),
+ )
+
+ if (options.encodeAbi) {
+ _options.data = txObject.encodeABI()
+ _options.to = token
+ return _options
+ }
+
+ return this.web3Client.send(txObject, _options)
+ }
+
approveERC20TokensForDeposit(
token: address,
amount: BN | string,

transfer erc721 tokens