ABI Encoding for offline method calls
See original GitHub issueHi ! I’m using ethers in combination with web3 in order to achieve the following:
- have the user import his json wallet/restore from mnemonic
- connect to the smart contract
- create a transaction that calls a non-constant method of the SC (ethers)
- sign the transaction offline or client side
- send the transaction to any node I need this so that the user can be the only one with access to the wallet
It seems fine with simple methods, like those that pass integers. But I got issues with more complex data. The code I use is this:
w1 = new ethers.Wallet(priv, provider);
iface = new ethers.utils.Interface(contract_abi);
txdata = iface.functions[method].encode(args);
signonce = await w1.getTransactionCount();
tx = {
"from" : addr,
"to" : contract_address,
"gasLimit" : 1500000,
"gasPrice" : 2,
"nonce" : signonce,
"data" : txdata,
"value" : 0,
};
web3 = new Web3( new Web3.providers.HttpProvider(rpcEndpoint));
account = await web3.eth.accounts.privateKeyToAccount(priv);
stx1 = await web3.eth.accounts.signTransaction(tx, priv);
web3.eth.sendSignedTransaction(stx1.rawTransaction)
This part works well. The problem is creating agrs to be encoded. If a prameter is an int or a string, no problem.
var args = {"i":32};
But how do I encode bytes? arrays? addresses? I get errors about the format/type/length of the parameter
Any help/advice/feedback would be greatly appreciated.
TIA
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Ethereum Contract ABI - Encoding for functions with no ...
I am using eth.sendRawTransaction to call a function in my deployed smart contract. Everything is working fine when the functions have arguments ...
Read more >ABI details - Algorand Developer Portal
The ABI (Application Binary Interface) is a specification that defines the encoding/decoding of data types and a standard for exposing and invoking methods...
Read more >Contract ABI Specification — Solidity 0.8.17 documentation
This descriptive data is the encoding of an error and its arguments in the same way as data for a function call. As...
Read more >web3.eth.Contract — web3.js 1.0.0 documentation
Creates a transaction object for that method, which then can be called, send, estimated, or ABI encoded. The methods of this smart contract...
Read more >headlong: A Contract ABI and RLP Library for the JVM
headlong can parse any function signature or JSON description at runtime and do the type-checking of inputs before encoding and of outputs during...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Heya!
I also recommend you try out v5, which has a. simpler API for dealing with Interface and Contracts for offline signing.
This is all doable in v4 too, but v5 specifically added some API to make offline-signing easier. 😃
@xzbnm
Edit: Hey, I got a feeling that you probably don’t have a
populateTransaction
in a smart contract and you actually meant to create a populated tx fortransfer
method? If that’s the case: