With the Wallet Adapter
If you are using or planning to use the SUI Wallet Kit, please follow the setup below:
Installation
npm install @mysten/wallet-kitWallet Kit Provider usage
import { ConnectButton, WalletKitProvider } from "@mysten/wallet-kit";
export function App() {
return <WalletKitProvider>
<ConnectButton />
{/* Your application... */}
</WalletKitProvider>;
}Example
import "./App.css";
import { ConnectButton, useWalletKit } from "@mysten/wallet-kit";
import { TransactionBlock } from "@mysten/sui.js";
import { useEffect } from "react";
function App() {
const {
currentWallet,
currentAccount,
signTransactionBlock,
signAndExecuteTransactionBlock,
signMessage,
} = useWalletKit();
useEffect(() => {
// You can do something with `currentWallet` here.
}, [currentWallet]);
return (
<div className="App">
<ConnectButton />
<div>
<button
onClick={async () => {
const txb = new TransactionBlock();
const [coin] = txb.splitCoins(txb.gas, [txb.pure(1)]);
txb.transferObjects([coin], txb.pure(currentAccount!.address));
console.log(await signTransactionBlock({ transactionBlock: txb }));
}}
>
Sign Transaction
</button>
</div>
<div>
<button
onClick={async () => {
const txb = new TransactionBlock();
const [coin] = txb.splitCoins(txb.gas, [txb.pure(1)]);
txb.transferObjects([coin], txb.pure(currentAccount!.address));
console.log(
await signAndExecuteTransactionBlock({
transactionBlock: txb,
options: { showEffects: true },
})
);
}}
>
Sign + Execute Transaction
</button>
</div>
<div>
<button
onClick={async () => {
console.log(
await signMessage({
message: new TextEncoder().encode("Message to sign"),
})
);
}}
>
Sign message
</button>
</div>
</div>
);
}
export default App;
Additional documentation
You can find all essential and additional documentation inside Wallet Kit documentation.
Last updated