Skip to content

RPC (Remote Procedure Call)

Calling an action on a contract requires that the transaction that is signed and sent, contains specific types of values in the RPC part, that is expected to contain the identifier of the action, and the arguments, for the parameters the action defines. These arguments must be serialized according to the following specification.

To encode and decode the RPC payload for events and transactions, you have to know which argument types the action expects, since the actual meaning of bytes in the payload depends on the argument type.

The ABI Format holds exactly the meta-data needed for finding types of the arguments for each action.

PayloadRpc

::= action:Shortname arguments:ArgumentsRpc* => action(arguments)

The short name of an action is an u32 integer identifier that uniquely identifies the action within the smart contract. The short name is encoded as unsigned LEB128 format, which means that short names have variable lengths. It is easy to determine how many bytes a LEB128 encoded number contains by examining bit 7 of each byte.

ShortName

::= pre:0xnn* last:0xnn => action

(where pre is 0-4 bytes that are ≥0x80 and last <0x80)

The argument binary format depends on the type of the argument. The argument types for each action is defined by the contract, and can be read from the ABI format.

ArgumentRpc

::=

0xnn => u8/i8

(i8 is two's complement)

| 0xnn×2 => u16/i16

(big-endian, i16 is two's complement)

| 0xnn×4 => u32/i32

(big-endian, i32 is two's complement)

| 0xnn×8 => u64/i64

(big-endian, i64 is two's complement)

| 0xnn×16 => u128/i128

(big-endian, i128 is two's complement)

| 0xnn×32 => u256

(big-endian)

| b:0xnn => Boolean

(false if b==0, true otherwise)

| 0xnn×21 => Address

| 0xnn×32 => Hash

| 0xnn×33 => PublicKey

| 0xnn×65 => Signature

| 0xnn×96 => BlsPublicKey

| 0xnn×48 => BlsSignature

| elems:T×len => Array[T;len]

(containing the len values)

| len:LengthRpc utf8:0xnn×len => String

(with len UTF-8 encoded bytes)

| len:LengthRpc elems:T×len => Vec<T>

(containing the len elements)

| b:0x00 => Option::None

| b:0x01 arg:T => Option::Some<T>

| f1:ArgumentRpc ... fn:ArgumentRpc => Struct S {f1,f2,...,fn}

| variant:0xnn f1:ArgumentRpc ... fn:ArgumentRpc => Enum{variant,f1,f2,...,fn}

LengthRpc

::= 0xnn×4 => u32

(big-endian)

Partisia All Rights Reserved © 2023