import {
MsgBid,
ChainGrpcAuctionApi,
MsgBroadcasterWithPk,
} from '@injectivelabs/sdk-ts'
import { ChainId } from '@injectivelabs/ts-types'
import { INJ_DENOM, BigNumberInBase } from '@injectivelabs/utils'
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
const endpointsForNetwork = getNetworkEndpoints(Network.Mainnet)
const auctionApi = new ChainGrpcAuctionApi(endpointsForNetwork.grpc)
const injectiveAddress = 'inj1...'
/* format amount for bid, note that bid amount has to be higher than the current highest bid */
const amount = {
denom: INJ_DENOM,
amount: new BigNumberInBase(1).toWei(),
}
const latestAuctionModuleState = await auctionApi.fetchModuleState()
const latestRound = latestAuctionModuleState.auctionRound
/* create message in proto format */
const msg = MsgBid.fromJSON({
amount,
injectiveAddress,
round: latestRound,
})
const privateKey = '0x...'
/* broadcast transaction */
const txHash = await new MsgBroadcasterWithPk({
network: Network.Mainnet,
privateKey,
}).broadcast({
msgs: msg,
})
console.log(txHash)