MCPcopy Create free account
hub / github.com/cardstack/cardstack / bridgeToLayer2

Function bridgeToLayer2

packages/cardpay-cli/bridge.ts:67–97  ·  view source on GitHub ↗
(
  network: string,
  amount: string,
  receiverAddress: string | undefined,
  tokenAddress: string,
  mnemonic?: string
)

Source from the content-addressed store, hash-verified

65}
66
67export async function bridgeToLayer2(
68 network: string,
69 amount: string,
70 receiverAddress: string | undefined,
71 tokenAddress: string,
72 mnemonic?: string
73): Promise<void> {
74 const amountInWei = toWei(amount);
75
76 let web3 = await getWeb3(network, mnemonic);
77 let tokenBridge = await getSDK('TokenBridgeForeignSide', web3);
78 let assets = await getSDK('Assets', web3);
79 let { symbol } = await assets.getTokenInfo(tokenAddress);
80 receiverAddress = receiverAddress ?? (await web3.eth.getAccounts())[0];
81
82 let blockExplorer = await getConstant('blockExplorer', web3);
83
84 {
85 console.log(`Sending approve transaction request for ${amount} ${symbol}`);
86 let result = await tokenBridge.unlockTokens(tokenAddress, amountInWei);
87 console.log(`Approve transaction hash: ${blockExplorer}/tx/${result.transactionHash}`);
88 }
89
90 {
91 console.log(
92 `Sending relay tokens transaction request for ${amount} ${symbol} into layer 2 safe owned by ${receiverAddress}`
93 );
94 let result = await tokenBridge.relayTokens(tokenAddress, receiverAddress, amountInWei);
95 console.log(`Relay tokens transaction hash: ${blockExplorer}/tx/${result.transactionHash}`);
96 }
97}
98
99export async function awaitBridgedToLayer2(
100 network: string,

Callers 1

index.tsFile · 0.85

Calls 7

getWeb3Function · 0.90
getSDKFunction · 0.90
getConstantFunction · 0.90
getTokenInfoMethod · 0.65
unlockTokensMethod · 0.65
relayTokensMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected