Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

encodeFunctionCall #269

Closed
rextremotabaresDtt opened this issue Jul 28, 2020 · 1 comment
Closed

encodeFunctionCall #269

rextremotabaresDtt opened this issue Jul 28, 2020 · 1 comment
Labels
question Further information is requested

Comments

@rextremotabaresDtt
Copy link

rextremotabaresDtt commented Jul 28, 2020

I'm trying to replicate some code made on Ionic, which uses web3.js.
At a certain point, it calls web3.eth.abi.encodeFunctionCall but as far as I've looked throught the library it doesn't contain any similar feature.
Here's the snippet I'm trying to mirror:

const transaction = Object.assign({}, config_1.config.basicTransaction);
    transaction.gasLimit = 600000;
    const publicKeyCallData = web3.eth.abi.encodeFunctionCall(config_1.config.contractsAbi.registry.addKey, [publicKey]);
    transaction.data = web3.eth.abi.encodeFunctionCall(config_1.config.contractsAbi.manager.identity, [publicKeyCallData]);
    transaction.to = config_1.config.manager;
    return transaction;

So far I have this, trying to replicate the first encodeFunctionCall:

        let walletAddress = EthereumAddress(walletAddress)! // Your wallet address
        let contractMethod = "addKey" // Contract method you want to write
        let contractABI = """
<JSON with ABI>
"""
        let contractAddress = EthereumAddress("<Address>")!
        let abiVersion = 2 // Contract ABI version
        let parameters : [AnyObject] = [publicKey.toHexString() as AnyObject] // Parameters for contract method
        let extraData: Data = Data() // Extra data for contract method
        let contract = w3.contract(contractABI, at: contractAddress, abiVersion: abiVersion)!
        var options = TransactionOptions.defaultOptions
        options.from = walletAddress
        options.gasPrice = .manual(BigUInt(0))
        options.gasLimit = .manual(BigUInt(600000))
        let tx = contract.method(contractMethod, parameters: parameters, extraData: extraData, transactionOptions: options)
        
if let ethTransaction = try? tx?.assemble(), let hashSignature = ethTransaction.encode(forSignature: true, chainID: nil)?.toHexString(){
            print(hashSignature)
            return hashSignature
        }else {
            throw Error.pubKeyData
        }

I've tried to use assemble and encode the transaction trying to replicate encodeFunctionCall, which then I need to add as parameter to the second method, but this fails with "Failed to fetch gas estimate" and I'm clueless wether this is an issue with how I coded that function or with the Ionic - Swift translation I'm developing.

Can you elaborate on how to use web3.eth.abi.encodeFunctionCall on this library or if it's not supported at all?

@skywinder
Copy link
Collaborator

Hello. Now you can use this function:
https://github.com/matter-labs/web3swift/blob/e36e767eb2de26decb0c157aeef2d023a1175076/Sources/web3swift/EthereumABI/ABIEncoding.swift#L136

Close for now. Feel free to comment issue if you still need help. 👍

@skywinder skywinder added the question Further information is requested label Oct 7, 2020
@Iysbaera Iysbaera removed the question Further information is requested label Jun 10, 2021
@Iysbaera Iysbaera added the question Further information is requested label Jun 10, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants