Optional
layer2Signer: SignerPrivate
layer2Private
Optional
layer2the minimum and maximum withdrawal limits as a string in token units (we assume 18 decimals, i.e. wei
) for bridging a token to layer 1. This method is invoked with the layer 2 CPXD token address of the CPXD token being withdrawn.
let { min, max } = await tokenBridge.getWithdrawalLimits(daiTokenAddress);
This call will invoke the token bridge contract to relay tokens from a layer 2 safe into the account specified in layer 1.
let result = await tokenBridge.relayTokens(
layer2SafeAddress,
tokenAddress,
layer1RecipientAddress,
amountInWei
);
Optional
txnOptions: TransactionOptionsOptional
contractOptions: ContractOptionsThis call waits for the token bridge validators to perform their necessary signatures on the token bridge request from layer 2 to layer 1. After the bridge validators have signed the bridging request, this call will return a messageId
, encodedData
, and signatures
for the bridging request. These items can then be used to claim the bridged tokens in layer 1.
This method is invoked with:
await layer2Web3.eth.getBlockNumber()
TokenBridgeHomeSide.relayTokens
).let {
messageId,
encodedData,
signatures
} = await tokenBridge.waitForBridgingValidation(fromBlock, txnHash);
This call will listen for a TokensBridgedToSafe
event emitted by the TokenBridge home contract that has a recipient matching the specified address. The starting layer 2 block height should be captured before the call to relayTokens is made to begin bridging. It is used to focus the search and avoid matching on a previous bridging for this user.
promise that includes a web3 transaction receipt for the layer 2 transaction, from which you can obtain the transaction hash, ethereum events, and other details about the transaction https://web3js.readthedocs.io/en/v1.3.4/web3-eth-contract.html#id37.
We use the subgraph to act as our indicator that bridging has completed, as this is the same mechanism that is populating the card wallet's displayed token balances
let txnReceipt = await tokenBridge.waitForBridgingToLayer2Completed(
recipientAddress
startingBlockHeight,
);
The address of the layer 2 account that will own the resulting safe (passed as receiver to relayTokens call)
The block height of layer 2 before the relayTokens call was initiated on the foreign side of the bridge. Get it with await layer2Web3.eth.getBlockNumber()
Generated using TypeDoc
The
TokenBridgeHomeSide
API is used to bridge tokens into the layer 2 network in which the Card Protocol runs. TheTokenBridgeHomeSide
API can be obtained fromgetSDK()
with aWeb3
instance that is configured to operate on a layer 2 network (like Gnosis Chain or Sokol).Example