GitHub

References

Javascript Anchor Types Reference

This reference shows you how Anchor maps Rust types to JavaScript/TypeScript types in the client.


TypeRustTypeScriptExample

Boolean

boolboolean
true

Integer

u8/u16/u32/i8/i16/i32number
99

Big integer

u64/u128/i64/i128anchor.BN
new anchor.BN(99)

Float

f32/f64number
1.0

String

Stringstring
"hello"

Array

[T; N]Array<T>
[1, 2, 3]

Vector

Vec<T>Array<T>
[1, 2, 3]

Option

Option<T>T | null | undefinedNone:
null
Some(val):
42

Struct

Structobject
struct MyStruct {
  val: u16,
}
{ val: 99 }

Enum

Enumobject
enum MyEnum {
    One,
    Two { val: u32 },
    Three(u8, i16),
}
Unit variant:
{ one : {} }
Named variant:
{ two: { val: 99 } }
Unnamed (tuple) variant:
{ three: [12, -34] }
Previous
Rust Client Library