The Stack Overflow podcast is back! Listen to an interview with our new CEO.
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 "...


4

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)...


4

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" ...


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

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) { ...


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

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


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

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

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

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" ...


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 string (name) and a static bool (isFirst). When encoding the parameters, the EVM looks to see if the parameters are static or dynamic. Static ...


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

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

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 ...


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 ...


1

I don't know if there is any native library available in Solidity, but there are node-js libraries available will help you do that. I also found this solidity code when doing a search on RLP, have a look at the code snippet below: https://github.com/Giveth/milestonetracker/blob/master/contracts/RLP.sol Libraries: https://www.npmjs.com/package/rlp ...


1

From various places in the Geth code, it looks like it's defined (and handled) as a BigInt. (The actual upper limit will be architecture dependent.) For example, in config.go: // MainnetChainConfig is the chain parameters to run a node on the main network. MainnetChainConfig = &ChainConfig{ ChainId: big.NewInt(1), I'd assume that the other ...


1

I don't believe there's any built-in function for doing this, but here's a toBase58 implementation: https://github.com/MrChico/verifyIPFS/blob/master/contracts/verifyIPFS.sol#L28. Depending on your use case, it might be better to have Solidity deal with the raw bytes and convert to/from base58 outside of the contract (e.g. in JavaScript or whatever client ...


1

I do not know why this error is occuring, but: I'm on ubuntu, and file -i keyfile gives the same result as for you. As I have no problem with my key, it is probably not an encoding problem in your side. The '{' character is used to format the keyfile. My file format is: {"address":x,"crypto":{"cipher":"aes-128-ctr","ciphertext":x,"cipherparams":{"iv":x},...


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