Injective 支持 Ethereum 和 Cosmos 原生钱包。你可以使用 Metamask、Ledger、Keplr、Leap 等流行钱包在 Injective 上签署交易。
Wallet Strategy
支持所有这些钱包的推荐方式是使用我们构建的 WalletStrategy 抽象。这种方法将使你的 dApp 用户能够连接和使用不同的钱包。
将其与 MsgBroadcaster 抽象结合使用,可以通过一次函数调用来签署交易。这是 Helix、Hub、Explorer 等所有产品中使用的方式,我们强烈建议在你的 dApp 中使用这种方法。
如果你仍然想原生使用某些钱包(不使用 WalletStrategy 类),我们将在本文档中提供如何通过 Metamask 和 Keplr 连接到基于 Injective 构建的 dApp 的示例。
Metamask 是一个 Ethereum 原生钱包,可用于连接和与基于 Injective 构建的 dApp 交互。
- 从 Metamask 获取 Injective 地址
import { getInjectiveAddress } from "@injectivelabs/sdk-ts/utils";
const getEthereum = () => {
if (!window.ethereum) {
throw new Error("Metamask extension not installed");
}
return window.ethereum;
};
const ethereum = getEthereum();
const addresses = await ethereum.request({
method: "eth_requestAccounts",
}); /** these are evm addresses */
const injectiveAddresses = addresses.map(getInjectiveAddress);
console.log(injectiveAddresses);
如何在 Injective 上使用 Metamask 准备 + 签署 + 广播交易的示例可以在这里找到。
Keplr
Keplr 是一个 Cosmos 原生钱包,可用于连接和与基于 Injective 构建的 dApp 交互。
import { ChainId } from "@injectivelabs/ts-types";
const getKeplr = () => {
if (!window.keplr) {
throw new Error("Keplr extension not installed");
}
return window.keplr;
};
(async () => {
const keplr = getKeplr();
const chainId = ChainId.Mainnet;
await keplr.enable(chainId);
const injectiveAddresses = await keplr
.getOfflineSigner(chainId)
.getAccounts();
console.log(injectiveAddresses);
})();
如何在 Injective 上使用 Keplr 准备 + 签署 + 广播交易的示例可以在 Cosmos Transactions 中找到。 Last modified on April 3, 2026