github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/reference/stdlibs/std/chain.md (about) 1 --- 2 id: chain 3 --- 4 5 # Chain-related 6 7 ## IsOriginCall 8 ```go 9 func IsOriginCall() bool 10 ``` 11 Checks if the caller of the function is an EOA. Returns **true** if caller is an EOA, **false** otherwise. 12 13 #### Usage 14 ```go 15 if !std.IsOriginCall() {...} 16 ``` 17 --- 18 19 ## AssertOriginCall 20 ```go 21 func AssertOriginCall() 22 ``` 23 Panics if caller of function is not an EOA. 24 25 #### Usage 26 ```go 27 std.AssertOriginCall() 28 ``` 29 --- 30 31 ## Emit 32 ```go 33 func Emit(typ string, attrs ...string) 34 ``` 35 Emits a Gno event. Takes in a **string** type (event identifier), and an even number of string 36 arguments acting as key-value pairs to be included in the emitted event. 37 38 #### Usage 39 ```go 40 std.Emit("MyEvent", "myKey1", "myValue1", "myKey2", "myValue2") 41 ``` 42 --- 43 44 ## CurrentRealmPath 45 ```go 46 func CurrentRealmPath() string 47 ``` 48 Returns the path of the realm it is called in. 49 50 #### Usage 51 ```go 52 realmPath := std.CurrentRealmPath() // gno.land/r/demo/users 53 ``` 54 --- 55 56 ## GetChainID 57 ```go 58 func GetChainID() string 59 ``` 60 Returns the chain ID. 61 62 #### Usage 63 ```go 64 chainID := std.GetChainID() // dev | test3 | main ... 65 ``` 66 --- 67 68 ## GetHeight 69 ```go 70 func GetHeight() int64 71 ``` 72 Returns the current block number (height). 73 74 #### Usage 75 ```go 76 height := std.GetHeight() 77 ``` 78 --- 79 80 ## GetOrigSend 81 ```go 82 func GetOrigSend() Coins 83 ``` 84 Returns the `Coins` that were sent along with the calling transaction. 85 86 #### Usage 87 ```go 88 coinsSent := std.GetOrigSend() 89 ``` 90 --- 91 92 ## GetOrigCaller 93 ```go 94 func GetOrigCaller() Address 95 ``` 96 Returns the original signer of the transaction. 97 98 #### Usage 99 ```go 100 caller := std.GetOrigSend() 101 ``` 102 --- 103 104 ## GetOrigPkgAddr 105 ```go 106 func GetOrigPkgAddr() string 107 ``` 108 Returns the address of the first (entry point) realm/package in a sequence of realm/package calls. 109 110 #### Usage 111 ```go 112 origPkgAddr := std.GetOrigPkgAddr() 113 ``` 114 --- 115 116 ## CurrentRealm 117 ```go 118 func CurrentRealm() Realm 119 ``` 120 Returns current Realm object. 121 122 [//]: # (todo link to realm type explanation) 123 #### Usage 124 ```go 125 currentRealm := std.CurrentRealm() 126 ``` 127 --- 128 129 ## PrevRealm 130 ```go 131 func PrevRealm() Realm 132 ``` 133 Returns the previous caller realm (can be code or user realm). If caller is a 134 user realm, `pkgpath` will be empty. 135 136 #### Usage 137 ```go 138 prevRealm := std.PrevRealm() 139 ``` 140 --- 141 142 ## GetCallerAt 143 ```go 144 func GetCallerAt(n int) Address 145 ``` 146 Returns the n-th caller of the function, going back in the call trace. 147 148 #### Usage 149 ```go 150 currentRealm := std.GetCallerAt(1) // returns address of current realm 151 previousRealm := std.GetCallerAt(2) // returns address of previous realm/caller 152 std.GetCallerAt(0) // error, n must be > 0 153 ``` 154 --- 155 156 ## DerivePkgAddr 157 ```go 158 func DerivePkgAddr(pkgPath string) Address 159 ``` 160 Derives the Realm address from its `pkgpath` parameter. 161 162 #### Usage 163 ```go 164 realmAddr := std.DerivePkgAddr("gno.land/r/demo/tamagotchi") // g1a3tu874agjlkrpzt9x90xv3uzncapcn959yte4 165 ```