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

Function bridgeToLayer1

packages/cardpay-cli/bridge.ts:7–28  ·  view source on GitHub ↗
(
  network: string,
  safeAddress: string,
  tokenAddress: string,
  receiverAddress: string,
  amount: string,
  mnemonic?: string
)

Source from the content-addressed store, hash-verified

5const { toWei } = Web3.utils;
6
7export async function bridgeToLayer1(
8 network: string,
9 safeAddress: string,
10 tokenAddress: string,
11 receiverAddress: string,
12 amount: string,
13 mnemonic?: string
14): Promise<void> {
15 const amountInWei = toWei(amount);
16
17 let web3 = await getWeb3(network, mnemonic);
18 let tokenBridge = await getSDK('TokenBridgeHomeSide', web3);
19 let assets = await getSDK('Assets', web3);
20 let { symbol } = await assets.getTokenInfo(tokenAddress);
21 receiverAddress = receiverAddress ?? (await web3.eth.getAccounts())[0];
22
23 let blockExplorer = await getConstant('blockExplorer', web3);
24
25 console.log(`Bridging ${amount} ${symbol} from layer 2 safe ${safeAddress} to layer 1 account ${receiverAddress}...`);
26 let result = await tokenBridge.relayTokens(safeAddress, tokenAddress, receiverAddress, amountInWei);
27 console.log(`Approve transaction hash: ${blockExplorer}/tx/${result.transactionHash}`);
28}
29
30export async function awaitBridgedToLayer1(
31 network: string,

Callers 1

index.tsFile · 0.70

Calls 6

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

Tested by

no test coverage detected