SDK Types

Lets discuss which types smart contracts use to input and output data, as well as how such data is stored and handled in the contract’s code.

### Native Types
Smart contracts can receive, store and return data using JS native types:
– `string`
– `number`
– `boolean`
– `Array`
– `Map`
– `Object`
– `BigInt`

### Native Types
Smart contracts can receive, store and return data using the following Rust types:
– `string`
– `i8-i32/u8-u32`
– **`u64/128`**: It is preferable to use SDK types `U64` and `U128`
– `bool`
– `HashMap`
– `Vector`

### Complex Objects
Smart contracts can store and return complex objects

**Note:** Objects will always be received and returned as JSON

#### Serializers
Objects that will be used as input or output need to be serializable to JSON, add the `#[near(serializer=json)]` macro

Objects that will be stored in the contract’s state need to be serializable to Borsh, add the `#[near(serializer=borsh)]` macro

### Handling Tokens
`$NEAR` tokens are typed as `BigInt` in JS, and their values represented in `yoctonear`

**Note:** 1 NEAR = 10^24 yoctoNEAR

### Handling Tokens
`$NEAR` tokens are handled through the `NearToken` struct, which exposes methods to represent the value in `yoctonear`, `milinear` and `near`

**Note:** 1 NEAR = 10^24 yoctonear

### Account
The SDK exposes a special type to handle NEAR Accounts, which automatically checks if the account address is valid

Generate comment with AI 2 nL
Scroll to Top