KNOV
KNOV

Reputation: 21

encoding typescript lib "solana/buffer-layout"

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>'

Upvotes: 2

Views: 1044

Answers (1)

Jon C
Jon C

Reputation: 8472

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:

const lo = require('@solana/buffer-layout');
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"),
])

Upvotes: 2

Related Questions