diff --git a/.changeset/fresh-clouds-compete.md b/.changeset/fresh-clouds-compete.md new file mode 100644 index 00000000..39ce708f --- /dev/null +++ b/.changeset/fresh-clouds-compete.md @@ -0,0 +1,8 @@ +--- +"@aptos-labs/wallet-adapter-nextjs-example": major +"@aptos-labs/aptos-wallet-plugin": major +"@aptos-labs/wallet-adapter-core": major +"@aptos-labs/wallet-adapter-react": major +--- + +Add support to submit BCS transaction diff --git a/apps/nextjs-example/pages/index.tsx b/apps/nextjs-example/pages/index.tsx index b2e74137..c17b11de 100644 --- a/apps/nextjs-example/pages/index.tsx +++ b/apps/nextjs-example/pages/index.tsx @@ -1,4 +1,4 @@ -import { AptosClient, Types } from "aptos"; +import { AptosClient, BCS, TxnBuilderTypes, Types } from "aptos"; import { useWallet } from "@aptos-labs/wallet-adapter-react"; import { WalletSelector } from "@aptos-labs/wallet-adapter-ant-design"; import { WalletConnector } from "@aptos-labs/wallet-adapter-mui-design"; @@ -36,6 +36,37 @@ export default function App() { const [successAlertMessage, setSuccessAlertMessage] = useState(""); const [errorAlertMessage, setErrorAlertMessage] = useState(""); + const onSignAndSubmitBCSTransaction = async () => { + const token = new TxnBuilderTypes.TypeTagStruct( + TxnBuilderTypes.StructTag.fromString("0x1::aptos_coin::AptosCoin") + ); + const entryFunctionBCSPayload = + new TxnBuilderTypes.TransactionPayloadEntryFunction( + TxnBuilderTypes.EntryFunction.natural( + "0x1::coin", + "transfer", + [token], + [ + BCS.bcsToBytes( + TxnBuilderTypes.AccountAddress.fromHex(account!.address) + ), + BCS.bcsSerializeUint64(2), + ] + ) + ); + + try { + const response = await signAndSubmitTransaction(entryFunctionBCSPayload); + await aptosClient.waitForTransaction(response?.hash || ""); + setSuccessAlertMessage( + `https://explorer.aptoslabs.com/txn/${response?.hash}` + ); + } catch (error: any) { + console.log("error", error); + setErrorAlertMessage(error); + } + }; + const onSignAndSubmitTransaction = async () => { const payload: Types.TransactionPayload = { type: "entry_function_payload", @@ -173,6 +204,17 @@ export default function App() { > Sign and submit transaction +