Bridge Native Transfers
Bridges are an essential part of the blockchain ecosystem. They allow users to send messages and transfer value from one chain to another. Often times, bridges aggregate messages from various users into a single transaction. This makes it difficult to track the flow of value across chains.
As an example, take this Arbitrum transaction that unwraps the WETH
token on the Arbitrum chain, and sends the native ETH to the wallet that initiated the transaction. We will set an address trigger on the wallet to notify us whenever the native token is transferred. The transfer can happen in either an internal, or a regular transaction.
{
"type": "TRIGGER_TYPE_ADDRESS",
"address": "0x14b76966dd9b45fd20e42f6e60384733184c2712"
}
// Create this function with an address trigger on your wallet.
export async function triggerHandler(context, data) {
if (context.dataType !== "DATA_TYPE_TRACE") {
return;
}
// Only CALL can be used to transfer native currency
if (data.type !== "CALL") {
return;
}
// Get triggered address from context
const walletAddress = context.trigger.address.address;
const lowerAddress = walletAddress.toLowerCase();
if (!data.to.includes(lowerAddress) && !data.from.includes(lowerAddress)) {
return;
}
const bigValue = BigInt(data.value);
if (bigValue === BigInt(0)) {
return;
}
return {
tokenSymbol: "ETH",
tokenName: "Ether",
tokenDecimals: 18,
sender: data.from,
receiver: data.to,
value: bigValue.toString(),
context: context,
};
}
Updated 29 days ago