I use truffle-contract for contract abstraction.

const myContract = TruffleContract(MyContractArtifact);


I'm using Infura as the web3 provider so need to sign transactions before sending them. If I want to use contract functions in the web3.eth.accounts.signTransaction data field, can this be done with the myContract instance? I understand it can be done with web3.eth.Contract based on this answer, so if it is actually possible, is it more or less the same technique, or what would I need to do?

Edit* I have given up on truffle-contract and using web3.eth.Contract.methods.myMethod.encodeABI()

Edi2* Changed title as I was wrong to say sendTransaction() - the method I require is sendSignedTransaction()

  • What are you trying to do? Do you want to create a "raw" to contract?
    – Ismael
    Jul 24, 2019 at 19:12
  • 1
    Sorry Ismael I'm not sure what that is. Basically, if truffle-contract has the equivalent of web3.eth.Contracts.method.encodeABI() (which is what you might have meant.) I have actually given up on truffle-contract and moved to the web3 contract abstraction, and have an offline signing solution in place that uses web3.eth.sendSignedTransaction Jul 24, 2019 at 20:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.