Smart contracts expose functions so users can interact with them. There are different types of functions including read-only, private and payable.
SDK types
Smart contracts can receive, store, and return data using native Rust types such as strings, integers, booleans, maps, and vectors. The SDK also provides types for values that need special handling at the contract boundary.
Large integers
Contracts can store u64 and u128 values directly, but JSON consumers cannot always represent them without losing precision. Use the SDK’s U64 and U128 wrapper types for public inputs and outputs that need to be serialized as strings.
JavaScript numbers cannot represent every integer above 2^53 - 1. Keep native integer types in internal contract logic, and use the JSON wrapper types at the external interface when necessary.
Complex objects
Contracts can receive and return complex Rust structures. Objects used as JSON inputs or outputs need JSON serialization, while structures stored in contract state need Borsh serialization.
See serialization for the difference between interface and state serialization.
Tokens and accounts
Use NearToken to represent NEAR amounts. It provides constructors and accessors for yoctoNEAR, millinear, and NEAR values.
The SDK’s AccountId type validates NEAR account IDs when values enter the contract. Prefer it to a plain String whenever a value represents an account.