forked from maticnetwork/matic.js
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request maticnetwork#19 from maticnetwork/feat-mapped-token
Feat mapped token
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,11 @@ const matic = new Matic({ | |
// Warning: Not-safe | ||
// matic.wallet = <private-key> // Use metamask provider or use WalletConnect provider instead. | ||
|
||
// get token address mapped with mainchain token address | ||
await matic.getMappedTokenAddress( | ||
tokenAddress // token address on mainchain | ||
) | ||
|
||
// Approve token for deposit | ||
await matic.approveTokensForDeposit( | ||
token, // Token address, | ||
|
@@ -116,6 +121,7 @@ Please write to [email protected] to request TEST tokens for development purpos | |
### API | ||
|
||
- <a href="#initialize"><code>new Matic()</code></a> | ||
- <a href="#getMappedTokenAddress"><code>matic.<b>getMappedTokenAddress()</b></code></a> | ||
- <a href="#approveTokensForDeposit"><code>matic.<b>approveTokensForDeposit()</b></code></a> | ||
- <a href="#depositTokens"><code>matic.<b>depositTokens()</b></code></a> | ||
- <a href="#depositEthers"><code>matic.<b>depositEthers()</b></code></a> | ||
|
@@ -156,6 +162,28 @@ const matic = new Matic(options) | |
|
||
--- | ||
|
||
<a name="getMappedTokenAddress"></a> | ||
|
||
#### matic.getMappedTokenAddress(tokenAddress) | ||
|
||
get matic token `address` mapped with mainchain `tokenAddress`. | ||
|
||
- `tokenAddress` must be valid token address | ||
|
||
This returns matic `address`. | ||
|
||
Example: | ||
|
||
```js | ||
matic | ||
.getMappedTokenAddress("0x670568761764f53E6C10cd63b71024c31551c9EC") | ||
.then(address => { | ||
console.log("matic address", address) | ||
}) | ||
``` | ||
|
||
--- | ||
|
||
<a name="approveTokensForDeposit"></a> | ||
|
||
#### matic.approveTokensForDeposit(token, amount, options) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const Matic = require('maticjs').default | ||
const config = require('./config') | ||
|
||
// 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, | ||
maticWethAddress: config.MATICWETH_ADDRESS, | ||
}) | ||
|
||
const tokenAddress = '0x670568761764f53E6C10cd63b71024c31551c9EC' // token address on mainchain | ||
|
||
matic.wallet = '<private-key>' // prefix with `0x` | ||
|
||
// get token address mapped with mainchain token address | ||
matic.getMappedTokenAddress(tokenAddress).then(() => { | ||
// action on Transaction success | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters