Integer
Type convertion​
CastToNat​
Convert a value of type TInt()
to TNat()
.
const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
CastToNat,
TInt,
TNat,
String,
} = require('@tezwell/smartts-sdk');
const contract = new Contract()
.setStorageType(TNat())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TInt())
.code((arg) => [
SetValue(ContractStorage(), CastToNat(arg, String('Could not convert int to nat'))),
]),
);
IsNat​
Convert a value of type TInt()
to TOption(TNat())
.
const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
IsNat,
GetSome,
TInt,
TNat,
String,
} = require('@tezwell/smartts-sdk');
const contract = new Contract()
.setStorageType(TNat())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TInt())
.code((arg) => [
SetValue(ContractStorage(), GetSome(IsNat(arg), String('Could not convert int to nat'))),
]),
);
CastToInt​
Convert a value of type TNat()
to TInt()
.
const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
CastToInt,
TInt,
TNat
} = require('@tezwell/smartts-sdk');
const contract = new Contract()
.setStorageType(TInt())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TNat())
.code((arg) => [
SetValue(ContractStorage(), CastToInt(arg)),
]),
);
ABS​
Obtain the absolute value of an TInt()
value.
const {
Contract,
EntryPoint,
SetValue,
ContractStorage,
ABS,
TInt,
TNat
} = require('@tezwell/smartts-sdk');
const contract = new Contract()
.setStorageType(TNat())
.addEntrypoint(
new EntryPoint('entry_point_1')
.setInputType(TInt())
.code((arg) => [
SetValue(ContractStorage(), ABS(arg)),
]),
);