-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontract.go
More file actions
31 lines (24 loc) · 769 Bytes
/
contract.go
File metadata and controls
31 lines (24 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package ethutils
import (
"strings"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
func PrepareContractBytecodeData(contractBin string, contractABIJSON string, constructorArgs []any) ([]byte, error) {
constructorBytecode, err := encodeConstructorArgs(contractABIJSON, constructorArgs)
if err != nil {
return nil, err
}
return append(common.Hex2Bytes(contractBin), constructorBytecode...), nil
}
func encodeConstructorArgs(contractABI string, constructorArgs []any) ([]byte, error) {
abi, err := abi.JSON(strings.NewReader(contractABI))
if err != nil {
return nil, err
}
constructorBytecode, err := abi.Pack("", constructorArgs...)
if err != nil {
return nil, err
}
return constructorBytecode, nil
}