import { TxRaw } from '@injectivelabs/sdk-ts'
import { Web3Exception } from '@injectivelabs/exceptions'
import { ChainId, EvmChainId } from '@injectivelabs/ts-types'
import { WalletStrategy } from '@injectivelabs/wallet-strategy'
const chainId = ChainId.Testnet // The Injective Testnet Chain ID
const evmChainId = EvmChainId.TestnetEvm // The Injective Evm Testnet Chain ID
export const alchemyRpcEndpoint = `https://eth-goerli.alchemyapi.io/v2/${process.env.APP_ALCHEMY_SEPOLIA_KEY}`
export const walletStrategy = new WalletStrategy({
chainId,
evmOptions: {
evmChainId,
rpcUrl: alchemyRpcEndpoint,
},
})
// Get wallet's addresses
export const getAddresses = async (): Promise<string[]> => {
const addresses = await walletStrategy.getAddresses()
if (addresses.length === 0) {
throw new Web3Exception(new Error('There are no addresses linked in this wallet.'))
}
return addresses
}
// Sign an Injective transaction
export const signTransaction = async (tx: TxRaw): Promise<string[]> => {
const response = await walletStrategy.signCosmosTransaction(
/*transaction:*/ { txRaw: tx, accountNumber: /* */, chainId: 'injective-1' },
/*address: */ 'inj1...',
)
return response
}
// Send an Injective transaction
export const sendTransaction = async (tx: TxRaw): Promise<string[]> => {
const response = await walletStrategy.sendTransaction(
tx,
// `sentryEndpoint` needed if Ethereum wallets are used
{address: 'inj1...', chainId: 'injective-1', sentryEndpoint: 'https://grpc.injective.network' }
)
return response
}