mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 14:54:21 +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
81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
// Bridge From Stacks
|
|
import {
|
|
BroSDK,
|
|
KnownTokenId,
|
|
KnownChainId,
|
|
BridgeFromStacksInput,
|
|
toSDKNumberOrUndefined,
|
|
BridgeFromStacksInput_ContractCallOptions as ContractCallOptions,
|
|
} from "@brotocol-xyz/bro-sdk"
|
|
import {
|
|
makeContractCall,
|
|
broadcastTransaction,
|
|
deserializeCV,
|
|
} from "@stacks/transactions"
|
|
|
|
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",
|
|
))!
|
|
|
|
const bridgeInfo = await sdk.bridgeInfoFromStacks({
|
|
fromChain: KnownChainId.Stacks.Mainnet,
|
|
toChain: KnownChainId.EVM.Ethereum,
|
|
fromToken: stacksToken,
|
|
toToken: evmToken,
|
|
amount: toSDKNumberOrUndefined(100_000_000),
|
|
})
|
|
|
|
console.log("Bridge Info:", bridgeInfo)
|
|
|
|
const bridgeFromStacksInput: BridgeFromStacksInput = {
|
|
fromChain: KnownChainId.Stacks.Mainnet,
|
|
toChain: KnownChainId.EVM.Ethereum,
|
|
fromToken: stacksToken,
|
|
toToken: evmToken,
|
|
fromAddress: "SP2ZD731ANQZT6J4K3F5N8A40ZXWXC1XFXHVVQFKE",
|
|
// Receiver EVM address
|
|
toAddress: "0x31751a152F1e95F966C041291644129144233b0B",
|
|
amount: toSDKNumberOrUndefined(100),
|
|
sendTransaction: async (tx: ContractCallOptions) => {
|
|
/**
|
|
* Implementation for sending transaction on Stacks mainnet.
|
|
* Refer to:
|
|
* - https://github.com/hirosystems/stacks.js/tree/main/packages/transactions#smart-contract-function-call
|
|
* - https://stacks.js.org/functions/_stacks_transactions.makeContractCall
|
|
* - https://stacks.js.org/functions/_stacks_transactions.broadcastTransaction
|
|
*/
|
|
const transaction = await makeContractCall({
|
|
contractAddress: tx.contractAddress,
|
|
contractName: tx.contractName,
|
|
functionName: tx.functionName,
|
|
// Deserialize each element of functionArgs and convert it into ClarityValue[]
|
|
functionArgs: tx.functionArgs.map(arg => deserializeCV(arg)),
|
|
postConditions: [] /* Add post conditions */,
|
|
validateWithAbi: true,
|
|
senderKey:
|
|
"b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01",
|
|
network: "mainnet",
|
|
})
|
|
|
|
const broadcastResponse = await broadcastTransaction({
|
|
transaction,
|
|
network: "mainnet",
|
|
})
|
|
return { txid: broadcastResponse.txid }
|
|
},
|
|
}
|
|
|
|
const result = await sdk.bridgeFromStacks(bridgeFromStacksInput)
|
|
console.log("Transaction ID:", result.txid)
|