People who code: we want your input. Take the Survey
7

go-ethereum abi package in Oct 2017 got the update to unpack event output. Initially it was only able to unpack method output. All functionality is delivered through the abi.ABI object. To use it you need to have Event ABI (JSON string). Then use func (abi *ABI) UnmarshalJSON to construct the ABI object. From there you can use the Unpack method using Data ...


6

The issue is that when you use a string literal like bytes public hardcodedCallData = "0x9461d6f7000000000000000000000000000000000000000000000000000000000000000a796f000000000000000000000000000000000000000000000000000000000000"; Solidity interprets the string as ASCII. In fact, if you do "...


6

With Brownie Brownie allows you to generate calldata using the ContractTx.encode_input method: >>> token <Token Contract object '0x79447c97b6543F6eFBC91613C655977806CB18b0'> >>> token.transfer.encode_input(accounts[0], 1000) ...


5

Web3.js doesn't provide a base58 encoder/decoder because it's only concerned with interfacing to ethereum, so there's no direct use of this feature. You'll have to use a module such as bs58. Here's an example: const bs58 = require('bs58') const BN = require('bn.js') const hash = 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU' const hex = bs58.decode(hash)...


5

Here's a full code example for anyone who's still confused (thanks to @Robert Zaremba's answer) package main import ( "context" "log" "math/big" "strings" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/myorg/myrepo/go-contracts/token" ...


4

Using BN.js as suggested by @Ismael: function numStringToBytes32(num) { var bn = new BN(num).toTwos(256); return padToBytes32(bn.toString(16)); } function bytes32ToNumString(bytes32str) { bytes32str = bytes32str.replace(/^0x/, ''); var bn = new BN(bytes32str, 16).fromTwos(256); return bn.toString(); } function padToBytes32(n) { ...


4

Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in two parameters: a dynamic string (name) and a static bool (isFirst). When encoding the parameters, the EVM looks to see if the parameters are static or dynamic. Static ...


3

This seems to be a remix bug. When you deploy it using web3 or so it should work properly. Everything should be fine. As the other answer stated you can bypass this problem.


3

If you don't want to pull your head off with arg encoding please note that there is now in web3JS vs 1.0 a method called encodeParameters Check also encodeFunctionCall that will encode the whole function + arguments If we take a look at the solidity doc Use of dynamic types we use the offset in bytes to the start of their data area, measured from the ...


3

The function signature (which is a 4 bytes code) is used internally in solidity to call the function. However for a user interface to show the user some readable information it is useful to lookup the function name, which can be done via https://www.4byte.directory. Clef integrates the entire 4bytes database to provide the same information. Developers can ...


3

https://www.npmjs.com/package/solidity-rlp Here is a package I am maintaining to decode rlp bytes in solidity. you can checkout the code and usage instructions here: https://github.com/hamdiallam/solidity-rlp


3

They are encoded using solidity abi The first 32 bytes is the offset where string is present within the response: 0000000000000000000000000000000000000000000000000000000000000020. So the string starts at position 20h = 32. At specified offset the first 32 bytes indicates the length of the string: ...


2

Here's how I did it using the ABI: path, _ := filepath.Abs("./resources/etherdelta.abi") file, err := ioutil.ReadFile(path) if err != nil { fmt.Println("Failed to read file:", err) } edabi, err := abi.JSON(strings.NewReader(string(file))) if err != nil { fmt.Println("Invalid abi:", err) } var orderStruct struct { TokenGet common.Address ...


2

uint is 256 bit, so everything is encoded correctly: first parameter: 14723a09acff6d2a60dcdf7aa4aff308fddc160c second parameter: 000000000000000000000000000000000000000000000000000000000000007b third parameter: 000000000000000000000000000000000000000000000000000000000000007b fourth parameter: 14723a09acff6d2a60dcdf7aa4aff308fddc160c it should not be ...


2

Using Ethereum's official golangs ABI is easy too: This is how you extract encoded values from transaction's input: m,exists:=erc20_token_abi.Methods[method_name] if exists { method_input,err:=m.Inputs.UnpackValues(input_data_bytes) } This is how you encode values for transaction's input : encoded_input,err:=contract_abi.Pack(method_name,...


2

I would check out the Web3.py library, specifically the function Web3.soliditySha3 This will work for computing the hash you need: from web3 import Web3 print(int(Web3.soliditySha3(['uint256', 'uint256', 'uint256'], [1 ,2, 3]), 16))


2

You can use the eth-abi library. >>> from eth-abi import encode_abi >>> encode_abi(['bytes32', 'bytes32'], [b'a', b'b']) b'a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\...


2

Is that correct? If yes, why do we do this and where can I find some further documentation? Yes, you are correct. Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in a dynamic parameter (bytes) as opposed to a static one ...


2

Yes, you can do it without going through javascript. Calling a function in a smart contract is just inputing the correct value in the data field of your transaction. Basically, an input is made of the 4 first bytes of the hash of the function's signature and following it, every value of the arguments padded to 32 bytes (if the arguments are of "simple" ...


2

Strictly speaking, there are no tuples in your example. Type uint8[] is a dynamic array type, not a tuple. Here is the encoding decomposed: 47958782 // Function selector (4 bytes) 0000000000000000000000000000000000000000000000000000000000000040 // Offset of the first argument (32 bytes) ...


2

Automatic getter functions of struct state variables will encode the struct data as if they were multiple return values, instead of returning one struct value. This is because before ABIEncoderV2, it was not possible to return a struct value. In this example, the getter function for aaa encodes the data exactly like function bbb: as multiple return values. ...


1

Yes they do. The easiest way to test it is by using remix and simply switching the complier version for both. If you take a look at the note in version 0.4.24 of the docs, you will see that this is true and the reason it was switched was to simply be more explicit. These encoding functions can be used to craft data for function calls without actually ...


1

Transactions are encoded based on the Contract ABI Specification. It is hard to get through, but these docs have all the answers to your question. The transaction in question is passing in two parameters: a dynamic array of addresses (_receivers) and a static uint256 (_value). When encoding the parameters, the EVM looks to see if the parameters are static ...


1

Yes, this is available in Solidity as abi.decode. You can see the documentation here https://solidity.readthedocs.io/en/v0.5.3/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions For example, your code would look something like (_amount, _receiver, _tokenLeadContract, _expectedAmount, _expectedSC) = abi.decode(_data, (...


1

It seems that you should do: my_contract.encodeABI (fn_name='my_method', args=[arg1, arg2, ...]) This is similar to Web3js: myContract.methods.myMethod.encodeABI (arg1, arg2, ...) See details in documentation.


1

Use contract.selector Example: For get contract use this code: def getInfo(abi, address): api = w3.eth.contract(address=address, abi=abi) return api def contractFunction(address, param1, param2): abi = """ json abi code """ return getInfo(abi, address).functions.contractFunction(param1, param2) And when you make ...


1

RLP is a method for serializing and deserializing data objects in a deterministic manner. Data stored on disk is RLP encoded into a compact Merkle Trie using a modified version of LevelDB. If you wish to have encrypted data, then the data being transacted must be encrypted beforehand and decrypted when reading.


1

As long as there is no relationship between your two private keys - ie, you didn't pick two that were in sequential order or something, then an attacker can't decrypt your private key based on any of that information. If the two keys were related in some way, then if they found one they may be able to guess the other. As for the other information, all ...


1

You probably want to refer to the hex representation of each. When using the hex representation, you see they are almost identical, differing only in the fact that python's cbor2 defines a static array of length 3, whilst the cbor library, simply uses a dynamically-sized array for efficiency and adaptability on-chain. Both conform to the cbor standard. ...


1

Try replacing the 2nd to last line with: var publicKey = ethutil.ecrecover(msgHash, (v & 1 ^ 1) + 27, r, s); Most of your code looks correct to me but the parity of the 2nd argument to ecrecover must be the same as the parity of the v value. So if the v value starts with the value 27, you can go through your calculation and check that your code would ...


Only top voted, non community-wiki answers of a minimum length are eligible