API
- new Matic()
- matic.balanceOfERC20()
- matic.balanceOfERC721()
- matic.tokenOfOwnerByIndexERC721()
- matic.depositEther()
- matic.approveERC20TokensForDeposit()
- matic.depositERC20ForUser()
- matic.safeDepositERC721Tokens()
- matic.transferERC20Tokens()
- matic.transferERC721Tokens()
- matic.startWithdraw()
- matic.startWithdrawForNFT()
- matic.withdraw()
- matic.withdrawNFT()
- matic.getTransferSignature()
- matic.transferWithSignature()
- matic.processExits()
WithdrawManager
- matic.withdrawManager.startExitForMintableBurntToken()
- matic.withdrawManager.startExitForMetadataMintableBurntToken()
new Matic(options)
Creates Matic SDK instance with give options. It returns a MaticSDK object.
options
is simple Javascriptobject
which can have following fields:maticProvider
can bestring
orWeb3.providers
instance. This provider must connect to Matic chain. Value can be anyone of following:- A free RPC URL that you can get from https://rpc.maticvigil.com/
new Web3.providers.HttpProvider('http://localhost:8545')
- WalletConnect Provider instance
parentProvider
can bestring
orWeb3.providers
instance. This provider must connect to Ethereum chain (testnet or mainchain). Value can be anyone of following:'https://ropsten.infura.io'
new Web3.providers.HttpProvider('http://localhost:8545')
- WalletConnect Provider instance
rootChain
must be valid Ethereum contract address.registry
must be valid Ethereum contract address.withdrawManager
must be valid Ethereum contract address.depositManager
must be valid Ethereum contract address.
matic.balanceOfERC20(userAddress, token, options)
get balance of ERC20 token
for address
.
token
must be valid token addressuserAddress
must be valid user addressoptions
see more infomation hereparent
must be boolean value. For balance on Main chain, useparent: true
This returns balance
.
Example:
matic.balanceOfERC721(userAddress, token, options)
get balance of ERC721 token
for address
.
token
must be valid token addressuserAddress
must be valid user addressoptions
see more infomation hereparent
must be boolean value. For balance on Main chain, useparent: true
This returns balance
.
Example:
matic.tokenOfOwnerByIndexERC721(userAddress, token, index, options)
get ERC721 tokenId at index
for token
and for address
.
token
must be valid token addressuserAddress
must be valid user addressindex
index of tokenId
This returns matic tokenId
.
Example:
matic.depositEthers(amount, options)
Deposit options.value
amount
must be token amount in wei (string, not in Number)options
see more infomation here.from
must be valid account address(required)encodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.approveERC20TokensForDeposit(token, amount, options)
Approves given amount
of token
to rootChainContract
.
token
must be valid ERC20 token addressamount
must be token amount in wei (string, not in Number)options
(optional) must be valid javascript object containingfrom
,gasPrice
,gasLimit
,nonce
,value
,onTransactionHash
,onReceipt
oronError
from
must be valid account address(required)gasPrice
same as EthereumsendTransaction
gasLimit
same as EthereumsendTransaction
nonce
same as EthereumsendTransaction
value
contains ETH value. Same as EthereumsendTransaction
. This returnsPromise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.depositERC20ForUser(token, user, amount, options)
Deposit given amount
of token
with user user
.
token
must be valid ERC20 token addressuser
must be value account addressamount
must be token amount in wei (string, not in Number)options
see more infomation hereencodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.safeDepositERC721Tokens(token, tokenId, options)
Deposit given TokenID
of token
with user user
.
token
must be valid ERC20 token addresstokenId
must be valid token IDoptions
see more infomation here
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.transferERC20Tokens(token, user, amount, options)
Transfer given amount
of token
to user
.
token
must be valid ERC20 token addressuser
must be value account addressamount
must be token amount in wei (string, not in Number)options
see more infomation hereparent
must be boolean value. For token transfer on Main chain, useparent: true
encodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.transferERC721Tokens(token, user, tokenId, options)
Transfer given tokenId
of token
to user
.
token
must be valid ERC721 token addressuser
must be value account addresstokenId
must be token amount in wei (string, not in Number)options
see more infomation hereparent
must be boolean value. For token transfer on Main chain, useparent: true
encodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.startWithdraw(token, amount, options)
Start withdraw process with given amount
for token
.
token
must be valid ERC20 token addressamount
must be token amount in wei (string, not in Number)options
see more infomation hereencodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.startWithdrawForNFT(token, tokenId, options)
Start withdraw process with given tokenId
for token
.
token
must be valid ERC721 token addresstokenId
must be token tokenId (string, not in Number)options
see more infomation hereencodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.withdraw(txId, options)
Withdraw tokens on mainchain using txId
from startWithdraw
method after header has been submitted to mainchain.
txId
must be valid tx hashoptions
see more infomation here
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.withdrawNFT(txId, options)
Withdraw tokens on mainchain using txId
from startWithdraw
method after header has been submitted to mainchain.
txId
must be valid tx hashoptions
see more infomation hereencodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
matic.getTransferSignature
Off-chain signature generation for transferWithSig function call
toSell
objecttoken
: address of token owned,amount
: amount/tokenId of the token to sell,expiry
: expiry (block number after which the signature should be invalid),orderId
: a random 32 byte hex string,spender
: the address approved to execute this transaction
toBuy
objecttoken
: address of token to buyamount
: amount/tokenId of token to buy
options
see more infomation herefrom
: owner of the token (toSell)
// sell orderlet toSell = {token: token2,amount: value2,expiry: expire,orderId: orderId,spender: spender,}// buy orderlet toBuy = {token: token1,amount: value1,}const sig = await matic.getTransferSignature(toSell, toBuy, {from: tokenOwner,})
matic.transferWithSignature
Executes transferWithSig on child token (erc20/721). Takes input as signature generated from matic.getTransferSignature
sig
: signature generated with matic.getTransferSignaturetoSell
: objecttoken
: address of token owned,amount
: amount/tokenId of the token to sell,expiry
: expiry (block number after which the signature should be invalid),orderId
: a random 32 byte hex string,spender
: the address approved to execute this transaction
toBuy
: objecttoken
: address of token to buyamount
: amount/tokenId of token to buy
orderFiller
: address of user to transfer the tokens tooptions
see more infomation herefrom
: the approved spender in thetoSell
object by the token owner
transfers toSell.token
from tokenOwner
to orderFiller
matic.processExits(rootTokenAddress, options)
Call processExits after completion of challenge period, after that withdrawn funds get transfered to your account on mainchain
rootTokenAddress
RootToken addressoptions
see more infomation hereencodeAbi
must be boolean value. For Byte code of transaction, useencodeAbi: true
This returns Promise
object, which will be fulfilled when transaction gets confirmed (when receipt is generated).
Example:
WithdrawManager
matic.withdrawManager.startExitForMintableBurntToken(burnTxHash, predicate: address, options)
See MintableERC721Predicate.startExitForMintableBurntToken
matic.withdrawManager.startExitForMintableBurntToken(burnTxHash, predicate: address, options)
See MintableERC721Predicate.startExitForMetadataMintableBurntToken
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
License
MIT