Every incoming message is sent from some contract that has an address.
You can query the address of the message sender by calling sender()
. Alternatively, the address is also available through context().sender
.
The sender during execution of the init()
method of the contract is the address who deployed the contract.
The main way to authenticate an incoming message, particularly for priviliges actions, is to verify the sender. This field is secure and impossible to fake.
import "@stdlib/deploy"; struct Point { x: Int as int64; y: Int as int64; } struct Params { name: String = "Satoshi"; // default value age: Int? = null; // optional field point: Point; // nested structs } message Add { point: Point; // message can hold a struct } contract Structs with Deployable { // contract persistent state variables s1: Point; s2: Params; init() { self.s1 = Point{x: 2, y: 3}; self.s2 = Params{point: self.s1}; } receive("show ops") { // temporary variable let s: Point = Point{x: 4, y: 5}; self.s1 = s; } receive(msg: Add) { self.s1.x = self.s1.x + msg.point.x; self.s1.y = self.s1.y + msg.point.y; } get fun point(): Point { return self.s1; } get fun params(): Params { return self.s2; } }