Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Trigger Polygon / MATIC Token Bridge via ethers.js
// See: https://github.com/maticnetwork/matic.js/blob/master/examples/POS-client/config.js
const posRootChainManager = '0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74';
const posERC20Predicate = '0xdD6596F2029e6233DEFfaCa316e6A95217d4Dc34';
const accounts = useAccounts();
const userAddress = accounts?.[0]
const rootDaiContract = useContractContext(DAIDummyContext, 0);
const { send: approve } = useContractFunc(rootDaiContract, "approve");
await approve(posERC20Predicate, amount);
const rootChainManagerContract = rootChainManagerContract__factory.connect(posRootChainManager, rootDaiContract.signer);
const { send: depositFor } = useContractFunc(rootChainManagerContract, "depositFor");
const depositData = ethers.utils.defaultAbiCoder.encode(['uint256'], [amount]);
await depositFor(userAddress, rootDaiContract.address, depositData);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment