mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 06:44:18 +08:00
commit a9488404b028aaeef5b7ab867a2392a969834fb0 Author: c4605 <bolasblack@gmail.com> Date: Mon May 12 23:36:07 2025 +0800 docs: optimize deps commita50d05dca2Author: sofinico <nicolettisofia1@gmail.com> Date: Wed May 7 16:50:43 2025 +0200 chore: address bro-sdk team review commit47fcf33525Merge:d13a68d2188881Author: 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 commitd13a68d4f8Author: sofinico <nicolettisofia1@gmail.com> Date: Tue May 6 17:18:15 2025 +0200 fix: add temporal patch to prevent `pnpm docs:watch` from failing commitfef755490fAuthor: sofinico <nicolettisofia1@gmail.com> Date: Tue May 6 17:15:20 2025 +0200 chore(docs): fix lint errors and remove unsed packages commitf8739f7f17Author: Facundo Lerena <faculerena@gmail.com> Date: Wed Apr 30 16:17:59 2025 -0300 docs: Update dev-instructions file. commit78de614697Author: Facundo Lerena <faculerena@gmail.com> Date: Wed Apr 30 16:06:12 2025 -0300 docs: Update Readme to address example location commit4592f31a85Author: Facundo Lerena <faculerena@gmail.com> Date: Wed Apr 30 16:05:45 2025 -0300 docs: Update `Bitcoin.ts` mock commit355bec1a9bMerge:a3f0e9a4fe7500Author: 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 commita3f0e9ab41Author: Facundo Lerena <faculerena@gmail.com> Date: Tue Apr 29 16:10:23 2025 -0300 docs: Remove `docs/readmeCodeSnippets.ts` commit23f725bfa9Author: Facundo Lerena <faculerena@gmail.com> Date: Tue Apr 29 16:08:55 2025 -0300 docs: Moved exampels into code-snippets, adressed comments in #20 commitf44e4382b7Merge:980907652d6e8cAuthor: Facundo Lerena <faculerena@gmail.com> Date: Tue Apr 29 11:48:05 2025 -0300 Merged snapshot commit9809076820Merge:f53158757f8b37Author: 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 commit57f8b3790fAuthor: Facundo Lerena <faculerena@gmail.com> Date: Fri Apr 25 15:29:48 2025 -0300 Docs: Update code snippets Added Runes and BRC20 bridging examples commitf5315877eeAuthor: sofinico <nicolettisofia1@gmail.com> Date: Fri Apr 25 17:47:04 2025 +0200 docs: address peer-review [wip] commit12d8f150e9Author: sofinico <nicolettisofia1@gmail.com> Date: Tue Apr 22 14:07:26 2025 +0200 docs: update readme basic operations and add table of contents commitc52e9b834aAuthor: 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 commitfcddf91a43Author: 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. commit029c19922dAuthor: sofinico <nicolettisofia1@gmail.com> Date: Tue Apr 22 11:05:19 2025 +0200 chore: add branded literal type doc commit13090aa374Author: sofinico <nicolettisofia1@gmail.com> Date: Tue Apr 22 11:04:53 2025 +0200 docs: create readme code snippets and dev instructions files done #20
80 lines
2.3 KiB
TypeScript
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)
|