# Create A Claim Type

Next we need to decide what claims our worker will report to the Oracle module. The Claim must implement the oracle's abstract Claim interface (opens new window).

Our claim will have two fields, price (usd price of Atom) and blockHeight - the point in time we are submitting our cliam.

The id for our cliam will be a constant string "AtomUsdClaim"

# Set The Claim Type constant

in x/<your_module>/types/keys.go add

Copy const AtomUsdClaim = "AtomUsdClaim"

# Create a proto Message for the claim:

add a new message inside the proto/<your_module> folder ex: https://github.com/relevant-community/oracle/tree/main/proto/atom/atom.proto

Copy message AtomUsd { string price = 1 [ (gogoproto.jsontag) = "price", (gogoproto.moretags) = "yaml:\"price\"", (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; int64 blockHeight = 2; }

# Implement the Claim interface of the Oracle Module

create a new file x/<your_module>/types/atomUsd.go

Copy package types import ( fmt "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto/tmhash" tmbytes "github.com/tendermint/tendermint/libs/bytes" ) // AtomUsd creates a new AtomUsd claim func NewAtomUsd(blockHeight int64, price string) *AtomUsd { decPrice, err := sdk.NewDecFromStr(price) if err != nil { return nil } return &AtomUsd{ Price: decPrice, BlockHeight: blockHeight, } } // Claim methods that implement the abstract Claim interface of the oracle module // ValidateBasic performs basic validation of the claim func (c *AtomUsd) ValidateBasic() error { if c.BlockHeight < 1 { return fmt.Errorf("invalid claim height: %d", c.BlockHeight) } return nil } // Type return type of oracle Claim func (c *AtomUsd) Type() string { return AtomClaim } // Hash returns the hash of an Claim Content. func (c *AtomUsd) Hash() tmbytes.HexBytes { bz, err := c.Marshal() if err != nil { panic(err) } return tmhash.Sum(bz) } // GetRoundID returns the block height for when the data was used. func (c *AtomUsd) GetRoundID() uint64 { return uint64(c.BlockHeight) } // GetConcensusKey returns a key the oracle will use of vote consensus // for deterministic results it should be the same as the hash of the content // for nondeterministic content it should be a constant func (c *AtomUsd) GetConcensusKey() string { return "" }

Note: because validators may return different prices within a given round, GetConsensusKey should return some constant value. This is because we will have a custom method to come to a 'consensus' about the results of the round.

# Register Our Claim Implementation

We need to make sure the serialization codec knows about our concrete type. Reg types/codec.go add:

Copy func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { registry.RegisterInterface( "relevantcommunity.oracle.oracle.Claim", (*exportedOracle.Claim)(nil), &AtomUsd{}, ) }

We are now ready to build our off-chian worker!