📜 [專欄新文章] Solidity Weekly #11
✍️ mingderwang
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
pure 跟 view 怎麼用?
在 Solidity 0.4.16 (含)之前,modifier constant 表示該 function 不會動到合約的 state (狀態), 例如:
string greeting;
function SayHello() public constant returns(string says) { return greeting;}
greeting 在 constructor 或其他地方, 已經有值,在這 SayHello() function 裡並沒有更動到 greeting 的值 (也就是合約的狀態)。
更正確的講,如果一個 function 不會改變到合約的 state,就可以加 modifier constant 在 returns 前面,因此在 web3.js 就可以用 call() 來呼叫該 function, 而不需要用 sendTransaction() 來呼叫。
到了 solc 0.4.17, 更把 constant 細分為 view 或 pure 兩種,只是程度上的不同。
view 一般來說,就用來取代 constant, 跟 compiler 説,該 function 不會對 storage state 有任何變動。(但會進行讀取, 所以 constant 改名為 view,更為恰當)
string greeting;
function SayHello() public view returns(string says) { return greeting;}
pure 定義該 function 連讀 storage state 都沒有。有人舉了一個誇張的例子如下:(它跟合約的所有 states 都無關, 可以加 modifier pure)
function returnTrue() public pure returns(bool response) { return true;}
links 分享;
Plasma Cash Simple Spec — (Karl Floersch)
Plasma Cash Initial Release — Plasma-Backed NFTs Now Available on Loom Network Sidechains — (Matthew Campbell)
https://github.com/loomnetwork/plasma-cash
https://github.com/omisego/plasma-cash
後記;
那麼有用 view 或 pure 有什麼好處?當然有了,以後 solc 最佳化, 可以因沒有 transaction, 而不需花 gas。現在這類的 function 也不必花時間到 network 去做確認造成 delay,也可以靠 compiler 檢查,避免 state 被意外修改。所以該加 view 或 pure 就要加。
*view 和 pure 取代 constant 開始於 solidity ^0.4.17
Solidity Weekly #11 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有1部Youtube影片,追蹤數超過25萬的網紅Pae CT,也在其Youtube影片中提到,http://www.facebook.com/paesyndrome ขอบคุณครับผม ติดต่อเรียนดนตรีพื้นฐานกับ แป๊ะ CT ได้ที่ 084-055-4188 ครับผม Guitar : Gibson SG Reissue 61 Gibson ...
「js to string」的推薦目錄:
- 關於js to string 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於js to string 在 Pae CT Youtube 的最佳解答
- 關於js to string 在 String to object in JS - Stack Overflow 的評價
- 關於js to string 在 JavaScript String Replace() Explained By Examples 的評價
- 關於js to string 在 Create slug from string in Javascript - gists · GitHub 的評價
- 關於js to string 在 JS 中的陣列trim 方法| Limitless Ping 的評價
- 關於js to string 在 HAUSER - Air on the G String (J. S. Bach) - YouTube 的評價
js to string 在 Pae CT Youtube 的最佳解答
http://www.facebook.com/paesyndrome ขอบคุณครับผม
ติดต่อเรียนดนตรีพื้นฐานกับ แป๊ะ CT ได้ที่ 084-055-4188 ครับผม
Guitar :
Gibson SG Reissue 61
Gibson SG Standard Limited Edition Cream White 2011
Gibson SG Standard Limited Edition Silverburst 2012
Gibson SG Standard Black(EMG81+85) 2005
Gibson SG Standard Blue 2010
Gibson SG Special Faded 2008
Gibson SG Standard Cherry 2005
Gibson SG Standard Cherry 2008 Seymour Duncan Phat Cat Neck Pickup 2008 (ขายแล้ว)
Gibson SG Standard Cherry 2005
Gibson SG Standard Black 2005
Gibson SG Standard Limited Edition Pelham Blue 2008
Gibson SG Standard Sunburst
Gibson SG Standard Cherry
Lavish Kleincaster
Lavish Hollovish
Lavish XG-1G
Lavish XG-2G
Lavish XG-1S Pink : Pae Syndrome Signature
Lavish PRS
Lavish JL-PW
Lavish LLP Ebony
Lavish SG
Ibanez AX7221
Baracuda ST
Washburn WR120
Yamaha F -210
Yamaha F -310
Baracuda OM-402
Schecter C1 Elite Amber
Schecter C1 Elite Black (ขายแล้ว)
Schecter C1 Elite White (ขายแล้ว)
Schecter C1 Classic
Schecter DAMIEN ELITE (ขายแล้ว)
Warwick Pro Series Corvette Standard Bubinga 5 สาย (ขายแล้ว)
Warwick Corvette Standard Bubinga 5 Germany (ขายแล้ว)
Fender Deluxe Active Precision Bass Special (ขายแล้ว)
Sterling by Music Man Ray35 (ขายแล้ว)
Sterling by Music Man JP60 Black (ขายแล้ว)
Sterling by Music Man JP70 (ขายแล้ว)
PRS SE Custom 24 ( 2013 ) (ขายแล้ว)
PRS SE Dave Navarro Signature
PRS SE Paul Allender ( new ) (ขายแล้ว)
LTD EC-401FM ม่วง (ขายแล้ว)
LTD EC-401FM เขียว (ขายแล้ว)
Washburn Dime V Pro
Washburn Tabu 300
Epiphone BASS THUNDERBIRD PRO 4 String
Epiphone Thunderbird Classic IV White
Epiphone Thunderbird Classic IV Sunburst (ขายแล้ว)
Schecter Synyster Custom A7X Signature
Warwick Thumb BO 5 Pro Series (ขายแล้ว)
Dolse TS-1E
Warwick Rockbass Corvette Basic 5 Nat (ขายแล้ว)
Warwick Rockbass Corvette Basic 5 White
Warwick corvette $$ 5 (ขายแล้ว)
Parker P38 (ขายแล้ว)
Schecter Omen Extreme (ขายแล้ว)
Epiphone 1966 G-400 PRO ( Limited Edition ) (ขายแล้ว)
Cort Artisan Pro ( Bartolini Pickup ) (ขายแล้ว)
Epiphone SG G-400 Alpine White (ขายแล้ว)
Burny Hide mg145s
Ovation USA Custom Legend 1719 (ขายแล้ว)
Epiphone Les Paul Zakk Wylde Custom Camo (ขายแล้ว)
Epiphone Les Paul Studio Gothic Black Satin (ขายแล้ว)
Fender Blacktop Stratocaster HH (ขายแล้ว)
Fender Blacktop Jaguar HH (ขายแล้ว)
Squier California Jazz Bass
Washburn Dime 333
Schecter V-1 Hellraiser FR
Sterling by Music Man JP60 Pearl Red Burst (ขายแล้ว)
Lavish XG-1S Blue : Pae Syndrome Signature
PRS SE Custom 22 (ขายแล้ว)
Epiphone Les Paul Zakk Wylde Custom Ivory
Mclorence SG (ขายแล้ว)
Epiphone Flying V Bass
Mclorence Ball
Lavish XG-1S ขาว (ขายแล้ว)
Schecter Omen-6 (ขายแล้ว)
Schecter Synyster Standard A7X Signature
Sterling by Music Man SUB Series Ray 4
Schecter Banshee-6 FR Active
SQUIER AVRIL LAVIGNE TELE Black
Schecter Hellraiser EXTREME C-1 MAPLE
Schecter C-1 Hellraiser
Schecter Banshee-6 Active (ขายแล้ว)
Ibanez RG350MZ
B.C.Rich Virgo
B.C.Rich Warlock Mick Thomson Signature Hate
Epiphone Custom Shop FireBird Limited Edition
Fender Jim Root(Slipknot) Telecaster
Washburn WI DLX
Ibanez GRGR121M-POP Pop Woravit (ขายแล้ว)
Schecter BLACKJACK SLS solo ACTIVE
Junior JE112
Epiphone 1966 G-400 PRO TV Silver ( Limited Edition )
Yamaha ERG121U
ibanez Bass
Baracuda Ton Dezember
Ibanez GRGR121EX
Schecter Stealth C-1
Lavish XG-1F Gold
Lavish CMRL-W
Sterling by Music Man SUB Series AX3
Squier Jim Root Tele
Squier Vintage Modified Jazz Bass 70
Squier California P-Bass
Sterling by Music Man SUB Series Ray 4
Baracuda Axcess Bass
Squier Vintage Modified Jazz Bass V
Epiphone BASS THUNDERBIRD PRO 5
Mclorence JP100
SQUIER California FAT STRAT RW
Schecter Tempest Custom
Squier Deluxe Jazz Bass Active V
Effect :
- Valeton Dapper
- Vox ToneLab EX
- Vox ToneLab ST
- Vox ToneLab LE
- Korg AX-3000G
- Boss GT-100
- Boss ME-25
- 8 Note Nightingale 2 Overdrive Pedal
- 8 Note Leon Drive Distortion Pedal
- 8 Note Chrono Tap Delay Pedal
- 8 Note Muscle Booster
- Bridge Line Pedal Metal End Crown
- Boss PH-3 Phase Shifter Pedal
- Korg Tuner Pitchblack PB01
- Shark Power Supply
- AKG WMS 40 Pro Flexx
- 8 Box Standard Pink Pae CT Signature
- Boss eBand JS-10
- BlackStar HT-Metal
- Boss TU-3
- Wireless AKG WMS45
- HH Guitar Amp SL30
- HH Bass Amp SB20
- Roland V-Drums TD-11K
- Roland V-Drums TD-11KV
- Roland V-Drum TD-4K2
- Roland OCTAPAD SPD-30
- Behringer XD8USB
- Behringer XENYX - 302 USB
- Behringer XENYX QX1222USB
- T.C. Electronic TC Helicon Harmony Singer
- Focusrite Scarlett 2i2 Studio
js to string 在 JavaScript String Replace() Explained By Examples 的推薦與評價
In this tutorial, you'll how to use JavaScript String replace() function to replace a substring in a string with a new one. ... <看更多>
js to string 在 Create slug from string in Javascript - gists · GitHub 的推薦與評價
Create slug from string in Javascript. GitHub Gist: instantly share code, notes, and snippets. ... <看更多>
js to string 在 String to object in JS - Stack Overflow 的推薦與評價
... <看更多>