|
| 1 | +## Nominal Changes |
| 2 | + |
| 3 | +These are changes to the way things are named, but the functionality remains the same. |
| 4 | + |
| 5 | +| TEALScript | PuyaTS | Notes | |
| 6 | +| ------------------------------------ | ----------------------------- | ------------------------------------------------ | |
| 7 | +| `GlobalStateKey` | `GlobalState` | | |
| 8 | +| `LocalStateKey` | `LocalState` | | |
| 9 | +| `BoxKey` | `BoxRef` | | |
| 10 | +| `prefix` | `keyPrefix` | The prefix option for BoxMap | |
| 11 | +| `this.txn` | `Txn` | | |
| 12 | +| `this.app` | `Global.currentApplicationId` | | |
| 13 | +| `isOptedInToApp`, `isOptedInToAsset` | `isOptedIn` | The Puya function accepts a union of these types | |
| 14 | +| `size` | `length` | The size of a box | |
| 15 | + |
| 16 | +## Minor Changes |
| 17 | + |
| 18 | +These are minor changes to the syntax of the language/API. |
| 19 | + |
| 20 | +| TEALScript | PuyaTS | Notes | |
| 21 | +| ------------------------------------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------ | |
| 22 | +| `this.boxRef.create(boxSize)` | `this.boxRef.create({ size: boxSize })` | The size option is now a property of the create method | |
| 23 | +| Explcicit method return types are required | Implicit method return types are allowed | | |
| 24 | +| `verify...Txn` | `assertMatch` | `assertMatch` accepts any object. This means, however, that txn types must be explicitly checked | |
| 25 | + |
| 26 | +## Major Changes |
| 27 | + |
| 28 | +These are major changes to the syntax of the language/API. |
| 29 | + |
| 30 | +### Method Routing |
| 31 | + |
| 32 | +#### TEALScript |
| 33 | + |
| 34 | +Each action (OnCompletes and create) has a method name that is used to route to the correct method when that action/OC is performed. |
| 35 | + |
| 36 | +```ts |
| 37 | +createApplication() { |
| 38 | +``` |
| 39 | +
|
| 40 | +#### PuyaTS |
| 41 | +
|
| 42 | +Decorators must be used to specify the action/OC. |
| 43 | +
|
| 44 | +```ts |
| 45 | +@abimethod({ onCreate: "require", allowActions: "NoOp" }) |
| 46 | +createApplication() { |
| 47 | +``` |
| 48 | +
|
| 49 | +### Native vs ABI types |
| 50 | +
|
| 51 | +#### TEALScript |
| 52 | +
|
| 53 | +TEALScript does ABI encoding/decoding automatically where appropriate. |
| 54 | +
|
| 55 | +```ts |
| 56 | +addToBox(x: uint64) { |
| 57 | + if (!this.boxOfArray.exists) { |
| 58 | + this.boxOfArray.value = [x]; |
| 59 | + } else { |
| 60 | + this.boxOfArray.value.push(x); |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | +
|
| 65 | +#### PuyaTS |
| 66 | +
|
| 67 | +Puya requires explicit ABI encoding/decoding in some scenarios, resulting in a "native" `uint64` type and a `UintN<64>` type. This also means that arrays must be initialized with a constructor rather than using array literals. |
| 68 | +
|
| 69 | +```ts |
| 70 | +addToBox(x: uint64) { |
| 71 | + if (!this.boxOfArray.exists) { |
| 72 | + this.boxOfArray.value = new DynamicArray(new UintN<64>(x)); |
| 73 | + } else { |
| 74 | + this.boxOfArray.value.push(new UintN<64>(x)); |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | +
|
| 79 | +### Math Typing |
| 80 | +
|
| 81 | +#### TEALScript |
| 82 | +
|
| 83 | +TEALScript supports math operators on any `uint<n>` type and returns the result as the same type. |
| 84 | +
|
| 85 | +```ts |
| 86 | +getSum(x: uint64, y: uint64): uint64 { |
| 87 | + const sum = x + y; |
| 88 | + return sum; |
| 89 | +} |
| 90 | +``` |
| 91 | +
|
| 92 | +#### PuyaTS |
| 93 | +
|
| 94 | +PuyaTS requires explicit usage of a constructor to return the result of a math operation. |
| 95 | +
|
| 96 | +```ts |
| 97 | +getSum(x: uint64, y: uint64): uint64 { |
| 98 | + const sum = UintN<64>(sum); |
| 99 | + return sum; |
| 100 | +} |
| 101 | +``` |
| 102 | +
|
| 103 | +### As Casting |
| 104 | +
|
| 105 | +#### TEALScript |
| 106 | +
|
| 107 | +TEALScript allows casting between types using the `as` keyword. |
| 108 | +
|
| 109 | +```ts |
| 110 | +const x: uint8 = 10; |
| 111 | +const y = x as uint64; |
| 112 | +``` |
| 113 | +
|
| 114 | +#### PuyaTS |
| 115 | +
|
| 116 | +PuyaTS does not support casting between types with `as`. Instead, the respective constructor must be used. |
| 117 | +
|
| 118 | +```ts |
| 119 | +const x: uint8 = 10; |
| 120 | +const y = UintN<64>(x); |
| 121 | +``` |
| 122 | +
|
| 123 | +### String vs Bytes |
0 commit comments