@@ -82,6 +82,7 @@ const main = async () => {
8282 console . log ( `Sending deposit transaction...` ) ;
8383
8484 let depositTx ;
85+ let nativeTokenDecimals = 18 ; // We default to 18 decimals for ETH and most of ERC-20 tokens
8586 if ( isCustomGasTokenChain ) {
8687 // Approve the gas token to be sent to the contract
8788 console . log ( 'Giving allowance to the contract to transfer the chain native token' ) ;
@@ -90,17 +91,20 @@ const main = async () => {
9091 ERC20__factory . abi ,
9192 parentChainWallet ,
9293 ) ;
94+ nativeTokenDecimals = await nativeToken . decimals ( ) ;
9395 const approvalTransaction = await nativeToken . approve (
9496 depositContract . address ,
95- ethers . utils . parseEther ( '1' ) ,
97+ ethers . utils . parseUnits ( '1' , nativeTokenDecimals ) ,
9698 ) ;
9799 const approvalTransactionReceipt = await approvalTransaction . wait ( ) ;
98100 console . log ( `Approval transaction receipt is: ${ approvalTransactionReceipt . transactionHash } ` ) ;
99101
100- depositTx = await depositContract . depositToChildChain ( ethers . utils . parseEther ( '0.01' ) ) ;
102+ depositTx = await depositContract . depositToChildChain (
103+ ethers . utils . parseUnits ( '0.01' , nativeTokenDecimals ) ,
104+ ) ;
101105 } else {
102106 depositTx = await depositContract . depositToChildChain ( {
103- value : ethers . utils . parseEther ( '0.01' ) ,
107+ value : ethers . utils . parseEther ( '0.01' ) , // Here we know we are using ETH, so we can use parseEther
104108 } ) ;
105109 }
106110 const depositReceipt = await depositTx . wait ( ) ;
@@ -176,7 +180,7 @@ const main = async () => {
176180 {
177181 from : contractAliasAddress ,
178182 to : transferTo ,
179- l2CallValue : ethers . utils . parseEther ( '0.01' ) , // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
183+ l2CallValue : ethers . utils . parseUnits ( '0.01' , nativeTokenDecimals ) , // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
180184 excessFeeRefundAddress : depositContract . address ,
181185 callValueRefundAddress : depositContract . address ,
182186 data : [ ] ,
@@ -204,7 +208,9 @@ const main = async () => {
204208 * we need to subtract it here so the transaction in the parent chain doesn't pay l2callvalue
205209 * and instead uses the alias balance on the child chain directly.
206210 */
207- const depositAmount = parentToChildMessageGasParams . deposit . sub ( ethers . utils . parseEther ( '0.01' ) ) ;
211+ const depositAmount = parentToChildMessageGasParams . deposit . sub (
212+ ethers . utils . parseUnits ( '0.01' , nativeTokenDecimals ) ,
213+ ) ;
208214
209215 console . log (
210216 `Transfer funds txn needs ${ ethers . utils . formatEther (
@@ -222,7 +228,7 @@ const main = async () => {
222228
223229 setTransferTx = await depositContract . moveFundsFromChildChainAliasToAnotherAddress (
224230 transferTo ,
225- ethers . utils . parseEther ( '0.01' ) , // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
231+ ethers . utils . parseUnits ( '0.01' , nativeTokenDecimals ) , // because we deposited 0.01 ether, so we also transfer 0.01 ether out here.
226232 parentToChildMessageGasParams . maxSubmissionCost ,
227233 parentToChildMessageGasParams . gasLimit ,
228234 gasPriceBid ,
0 commit comments