Skip to content

Instantly share code, notes, and snippets.

@heri16
Last active June 29, 2021 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heri16/cd383f19ffec5e6b8abf323391697042 to your computer and use it in GitHub Desktop.
Save heri16/cd383f19ffec5e6b8abf323391697042 to your computer and use it in GitHub Desktop.
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