# [Solidity] 智能合約函式名稱對Gas消耗的影響

`contract Test {    function b() public {    }}`

`contract Test {    function a() public {    }        function b() public {    }}`

`contract Test {    function b() public {    }`
`    function a() public {    }}`

`a: 0x0dbe671fb: 0x4df7e3d0`

`contract Test {    function a() public {    }`
`    function b() public {    }`
`    function f() public {    }}`

`a: 0x0dbe671fb: 0x4df7e3d0f: 0x26121ff0`

#### 參與排序的成員

`contract Test {    uint256 public a;`
`    function b() public {    }}`

b() 會消耗147 Gas。

#### 函式簽章

`function func() public {}`
`function func2(address[] addr, uint256 amount) public {}`

`func()func2(address[],uint256)`

`uint256 public a;address public b;mapping(address => uint256) public c;`

`a()b()c(address)`

#### Method ID

Method ID 的產生規則如下：

`keccack256(函式簽章) 取前四 bytes`

`0dbe671f81a573cff601b9c227db0ed2e5339d3e0a07edc45c42f315a9cb8f0f4df7e3d0fdffd35719c59893b4839a04b686be9ac7bec9cdd04a272e9ad7c62826121ff025a6ba40cf27bcfb7cd50bcb8eab64881826af3760564c9e1ffa71eb`

#### 結論

1. 減少公用成員
2. 將常用函式順位提高

`b_A6Q(): 0x0000e3fa`

Like what you read? Give Yi-Cyuan Chen a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.