Skip to content
On this page

About code generation

What Golang code will generate by what Cadence code?

Builtin types conversion

Numbers

CadenceGo
Int*big.Int
Int8int8
Int16int16
Int32int32
Int64int64
Int128*big.Int
Int256*big.Int
UInt*big.Int
UInt8uint8
UInt16uint16
UInt32uint32
UInt64uint64
UInt128*big.Int
UInt256*big.Int
Fix64int64
UFix64uint64

Other

CadenceGo
Stringstring
Characterstring
Addressstring
Pathstring
AnyStructany
AnyResourceany
Boolbool

Map

Map types will convert based on detected types.
Example(String):

CadenceGo
{String:String}map[string]string
{String:{String:String}}map[string]map[string]string
{String:{String:{String:String}}}map[string]map[string]map[string]string
......

Array and Slice

Array and slice types will also convert based on detected types.
Example(String slices):

CadenceGo
[String][]string
[[String]][][]string
[[[String]]][][][]string
......

Example(String arrays):

CadenceGo
[String:8][8]string
[[String:8]:16][16][8]string
[[[String:8]:16]:32][32][16][8]string
......

struct

The structs in Cadence will be convert to Golang struct. Example, from:

cadence
pub struct AStruct {
  pub var fieldA: String
  pub var fieldB: Int64
  
  pub fun setFielA(_ a: String) {
    self.fieldA = a
  }

  init() {
    self.fieldA = ""
    self.fieldB = 0
  }
}

To:

go
type AStruct struct {
  FieldA string `godence:"fieldA"`
  FieldB int64  `godence:"fieldB"`
}

In this example, fieldA in Cadence convert to FieldA in Go, because in Go, first letter of field name must be UPPERCASE or it cannot access from another package (More information in spec), and it has a tag with value godence:"fieldA", this tag will used by godence to find origin field in Cadence.

INFO

TODO: Explain why methods of struct ignored during generation

godence is a tool also developed by LemonNeko, it will used to do type conversion.

resource

INFO

TODO: docs coming soon...

event

INFO

TODO: docs coming soon...

enum

WARNING

TODO: currently not support...

contract

INFO

TODO: docs coming soon...