I followed the tutorial to bridge our ERC20 token into the Matic network. My code looks like this:
`const Matic = require('@maticnetwork/maticjs').default
const config = require('./config.json')
const from = config.FROM_ADDRESS // from address
// Create object of Matic
const matic = new Matic({
maticProvider: config.MATIC_PROVIDER,
parentProvider: config.PARENT_PROVIDER,
rootChain: config.ROOTCHAIN_ADDRESS,
withdrawManager: config.WITHDRAWMANAGER_ADDRESS,
depositManager: config.DEPOSITMANAGER_ADDRESS,
registry: config.REGISTRY,
})
// async function execute() {
// await matic.initialize()
// matic.setWallet(config.PRIVATE_KEY)
// }
const token = config.MAINNET_ERC20 // ERC20 token address
const amount = '20' // amount in wei
async function execute() {
await matic.initialize()
matic.setWallet(config.PRIVATE_KEY)
// Approve Deposit Manager contract to transfer tokens
await matic.approveERC20TokensForDeposit(token, amount, { from, gasPrice: '10000000000' });
console.log('Approval done...');
// Deposit tokens
return matic.depositERC20ForUser(token, from, amount, { from, gasPrice: '10000000000' })
}
console.log('starting...');
execute();`
{ "MATIC_PROVIDER": "https://rpc-mainnet.matic.network", "PARENT_PROVIDER": "https://mainnet.infura.io/v3/60df93ecf023472aaa84725af955fde2", "ROOTCHAIN_ADDRESS": "0x2890bA17EfE978480615e330ecB65333b880928e", "WITHDRAWMANAGER_ADDRESS": "0x2923C8dD6Cdf6b2507ef91de74F1d5E0F11Eac53", "DEPOSITMANAGER_ADDRESS": "0x7850ec290A2e2F40B82Ed962eaf30591bb5f5C96", "PRIVATE_KEY": "_MY_PRIVATE_KEY_HERE_, "FROM_ADDRESS": "0x3115b321904572e05b4C2E5DC3e55628110593EE", "GOERLI_ERC20": "0x655f2166b0709cd575202630952d71e2bb0d61af", "MATIC_ERC20": "0x2d7882beDcbfDDce29Ba99965dd3cdF7fcB10A1e", "REGISTRY": "0xeE11713Fe713b2BfF2942452517483654078154D", "MUMBAI_ERC721":"0xa38c6F7FEaB941160f32DA7Bbc8a4897b37876b5", "GOERLI_ERC721":"0x0217B02596Dfe39385946f82Aab6A92509b7F352", "MUMBAI_WETH":"0x4DfAe612aaCB5b448C12A591cD0879bFa2e51d62", "GOERLI_WETH":"0x60D4dB9b534EF9260a88b0BED6c486fe13E604Fc", "MAINNET_ERC20":"0xdacd69347de42babfaecd09dc88958378780fb62" }
However, when I run the app using node matic-example.js, I get the following error::
(node:58539) UnhandledPromiseRejectionWarning: Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
at ABICoder.decodeParametersWith (/Users/nikola/Projects/matic-js-test/node_modules/web3-eth-abi/lib/index.js:298:15)
at ABICoder.decodeParameters (/Users/nikola/Projects/matic-js-test/node_modules/web3-eth-abi/lib/index.js:285:17)
at Contract._decodeMethodReturn (/Users/nikola/Projects/matic-js-test/node_modules/web3-eth-contract/lib/index.js:470:22)
at Method.outputFormatter (/Users/nikola/Projects/matic-js-test/node_modules/web3-eth-contract/lib/index.js:760:42)
at Method.formatOutput (/Users/nikola/Projects/matic-js-test/node_modules/web3-core-method/lib/index.js:147:54)
at sendTxCallback (/Users/nikola/Projects/matic-js-test/node_modules/web3-core-method/lib/index.js:523:33)
at /Users/nikola/Projects/matic-js-test/node_modules/web3-core-requestmanager/lib/index.js:308:9
at XMLHttpRequest.request.onreadystatechange (/Users/nikola/Projects/matic-js-test/node_modules/web3-providers-http/lib/index.js:98:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/nikola/Projects/matic-js-test/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/Users/nikola/Projects/matic-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/Users/nikola/Projects/matic-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage. (/Users/nikola/Projects/matic-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1244:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)