Files
bro-sdk/examples/bridgeFrom/EVM.ts
c4605 f5b572eebd Squashed commit of the following:
commit a9488404b028aaeef5b7ab867a2392a969834fb0
Author: c4605 <bolasblack@gmail.com>
Date:   Mon May 12 23:36:07 2025 +0800

    docs: optimize deps

commit a50d05dca2
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Wed May 7 16:50:43 2025 +0200

    chore: address bro-sdk team review

commit 47fcf33525
Merge: d13a68d 2188881
Author: Sofía <36451685+sofinico@users.noreply.github.com>
Date:   Tue May 6 17:36:14 2025 +0200

    Merge branch 'snapshots/v0.5' into feat/update-v0.5-readme

commit d13a68d4f8
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue May 6 17:18:15 2025 +0200

    fix: add temporal patch to prevent `pnpm docs:watch` from failing

commit fef755490f
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue May 6 17:15:20 2025 +0200

    chore(docs): fix lint errors and remove unsed packages

commit f8739f7f17
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Wed Apr 30 16:17:59 2025 -0300

    docs: Update dev-instructions file.

commit 78de614697
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Wed Apr 30 16:06:12 2025 -0300

    docs: Update Readme to address example location

commit 4592f31a85
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Wed Apr 30 16:05:45 2025 -0300

    docs: Update `Bitcoin.ts` mock

commit 355bec1a9b
Merge: a3f0e9a 4fe7500
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Wed Apr 30 15:56:15 2025 -0300

    Merge branch 'snapshots/v0.5' of github.com:Brotocol-xyz/bro-sdk into feat/update-v0.5-readme

commit a3f0e9ab41
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Tue Apr 29 16:10:23 2025 -0300

    docs: Remove `docs/readmeCodeSnippets.ts`

commit 23f725bfa9
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Tue Apr 29 16:08:55 2025 -0300

    docs: Moved exampels into code-snippets, adressed comments in #20

commit f44e4382b7
Merge: 9809076 52d6e8c
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Tue Apr 29 11:48:05 2025 -0300

    Merged snapshot

commit 9809076820
Merge: f531587 57f8b37
Author: Sofía <36451685+sofinico@users.noreply.github.com>
Date:   Mon Apr 28 14:47:40 2025 +0200

    Merge pull request #2 from CoinFabrik/feat/update-v0.5-readme-runes-brc20

    Docs: Add code snippets for Runes and BRC20

commit 57f8b3790f
Author: Facundo Lerena <faculerena@gmail.com>
Date:   Fri Apr 25 15:29:48 2025 -0300

    Docs: Update code snippets

    Added Runes and BRC20 bridging examples

commit f5315877ee
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Fri Apr 25 17:47:04 2025 +0200

    docs: address peer-review [wip]

commit 12d8f150e9
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue Apr 22 14:07:26 2025 +0200

    docs: update readme basic operations and add table of contents

commit c52e9b834a
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue Apr 22 12:28:42 2025 +0200

    docs: update code snippets

    * Replace `getSupportedRoutes` with `getPossibleRoutes`
    * Ajust readmeCodeSnippets.ts to rebrand where applicable
    * Add note explaining `functionArgs` serialization design for bridge from Stacks
    * Add @types/node dev dependency for readmeCodeSnippets.ts

commit fcddf91a43
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue Apr 22 11:17:49 2025 +0200

    docs: update readme

    Changes include:

    * Removed static token support table and replaced it with SDK methods that dynamically retrieve supported tokens.
    * Replaced the supported chains table with a  bullet-point list for improved readability.
    * Added a "Basic Operations" section to introcude general usage patterns of the SDK.
    * Improved code snippets, with correspondace to the docs/readmeCodeSnippets.ts file for consistency.

commit 029c19922d
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue Apr 22 11:05:19 2025 +0200

    chore: add branded literal type doc

commit 13090aa374
Author: sofinico <nicolettisofia1@gmail.com>
Date:   Tue Apr 22 11:04:53 2025 +0200

    docs: create readme code snippets and dev instructions files

done #20
2025-05-23 11:59:50 +02:00

80 lines
2.3 KiB
TypeScript

// Bridge From EVM
import {
BroSDK,
KnownTokenId,
KnownChainId,
toSDKNumberOrUndefined,
BridgeFromEVMInput,
EVMAddress,
SDKNumber,
formatSDKNumber,
} from "@brotocol-xyz/bro-sdk"
// Choose your preferred web3 lib here
import { ethers } from "ethers"
const sdk = new BroSDK()
// For Stacks provide the contract address
const stacksToken: KnownTokenId.StacksToken =
(await sdk.stacksAddressToStacksToken(KnownChainId.Stacks.Mainnet, {
deployerAddress: "SP2XD7417HGPRTREMKF748VNEQPDRR0RMANB7X1NK",
contractName: "token-abtc",
}))!
// For EVM tokens provide the contract address
const evmToken: KnownTokenId.EVMToken = (await sdk.evmAddressToEVMToken(
KnownChainId.EVM.Ethereum,
"0x31761a152F1e96F966C041291644129144233b0B",
))!
// Example signer setup using ethers.js
const provider = new ethers.JsonRpcProvider(
"https://mainnet.someprovider.io/YOUR_PROJECT_ID",
)
const signer = new ethers.Wallet(
"000000000000000000000000000000000000000000000000000000000000002d",
provider,
)
const signerAddress = signer.address as `0x${string}`
const bridgeFromEVMInput: BridgeFromEVMInput = {
fromChain: KnownChainId.EVM.Ethereum,
toChain: KnownChainId.Stacks.Mainnet,
fromToken: evmToken,
toToken: stacksToken,
// Sender Ethereum address
fromAddress: signerAddress,
// Receiver Stacks principal
toAddress: "SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE",
amount: toSDKNumberOrUndefined(100),
sendTransaction: async (tx: {
from: EVMAddress // Sender Ethereum address
to: EVMAddress // Bridge Endpoint address
data: Uint8Array
recommendedGasLimit: SDKNumber
value?: SDKNumber
}): Promise<{ txHash: string }> => {
/**
* Implementation for sending transaction on Ethereum mainnet
* See https://docs.ethers.org/v6/api/contract/ for reference
*/
const txRequest = {
from: tx.from,
to: tx.to,
data: ethers.hexlify(tx.data),
gasLimit: formatSDKNumber(tx.recommendedGasLimit),
}
const sentTx = await signer.sendTransaction(txRequest)
const receipt = await sentTx.wait()
if (receipt === null) throw new Error("Transaction receipt is null")
return { txHash: receipt.hash }
},
}
// Perform the bridge operation
const result = await sdk.bridgeFromEVM(bridgeFromEVMInput)
console.log("Transaction ID:", result.txHash)