encoding typescript lib "solana/buffer-layout"

Viewed 147

error when I try to encode scheme from solana contract

const settingsSchema = lo.struct([
    lo.ns64("cost"),
    lo.u32("width"),
    lo.u32("height"),
    lo.u16("max_players"),
])

error message: Type 'UInt' is not assignable to type 'Layout<never>' Type 'NearInt64' is not assignable to type 'Layout<never>' Type 'Sequence<number>' is not assignable to type 'Layout<never>'

1 Answers

If you're in TypeScript, the buffer-layout package requires that you provide a type for the struct that you're creating. In your case, you can change this to:

interface Settings {
    cost: bigint,
    width: number,
    height: number,
    max_players: number,
}
const settingsSchema = lo.struct<Settings>([
    lo.ns64("cost"),
    lo.u32("width"),
    lo.u32("height"),
    lo.u16("max_players"),
])
Related