Go-Ethereum – How to Manually Craft Transaction Data in Golang WITHOUT Using ethclient

go-ethereumgolang

how do i manually craft tx data (the actual DATA field in a tx) in golang without ethclient? i am trying to craft tx data to be signed later. lets assume i am trying to call a solidity function like myFunc(bool, address, address, address[], uint)

all of the ethclient examples require connecting to some rpc with ethclient.Dial() which i cannot do.

thanks so much!

Best Answer

The data for the transaction sent to the contract consists of the signature of the function being called (4 bytes = 8 hex characters) followed by a list of parameters packed according to the rules set out here -https://ethereum.stackexchange.com/questions/113394/how-output-of-abi-encode-calculated

The signature of a function is defined as the first 4 bytes (8 hex characters) of the sha3-hash of its declaration string, in your example - "myFunc(bool,address,address,address[],uint)". Spaces and tabs should be removed from the declaration. In your case, the signature of the function will be f6fe3edf.

Related Topic