0

Sorry if question is duplicate . I tried to find answers in google but I don't know \how to search really . Here is my problem . Basic Smart contract gives you some sort of API to communicate with blockchain , when using in it's method

 var MyContract = web3.eth.contract(abiArray);
var contractInstance = MyContract.new([contructorParam1] [, contructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});

After you can do smth like

contractInstance.methodWhichIsDescribedInContract(foo,bar)

So basically all erc20 standart contract must implements methods for sending and receiving tokens so far . But if contract already has the interface why people use raw transactions ?

1) Is it possible to interact with blockchain without contract ?

2) Is it the case for using raw transaction ?

3) If we have smart contract does it mean we don't need raw transactions?

Thanks

Edit 1 Example of raw transaction

var tx = new ethereumjs.Tx({
  nonce: nonce,
  gasPrice: web3.toHex(web3.toWei('20', 'gwei')),
  gasLimit: 100000,
  to: address,
  value: 0,
  data: data,
});
tx.sign(ethereumjs.Buffer.Buffer.from(privateKey, 'hex'));

var raw = '0x' + tx.serialize().toString('hex');
web3.eth.sendRawTransaction(raw, function (err, transactionHash) {
  console.log(transactionHash);
});
1
  • Can you explain "why people use raw transactions?" What do you mean by "raw transactions?" Can you give an example of a raw transaction and an example of a transaction that is not "raw?"
    – user19510
    Commented Mar 30, 2018 at 9:40

1 Answer 1

0

Q1. Yes. You can, of course, use the native protocol which even includes simple ether transfers. You can also send raw transactions.

Q2. mmmm ... I would prefer to use ABI whenever possible, and it's always possible if you have the contract source. That leaves a fairly narrow band of situation, One such situation might be the idea of a general-purpose wallet that will let people send arbitrary data to arbitrary addresses without validating that the raw data makes sense in the context of the contract on the other side.

Q3. Generally, Yes. Especially in the case that you move up to a higher level of abstraction such as Truffle, then the preferred mode would be interacting with the well-delineated contract ABI and letting the tools construct the low-level interface for you.

Hope it helps.

2
  • Hello Rob thanks for reply . It is a bit confusing how to use private keys with smart contract .
    – Albert
    Commented Apr 2, 2018 at 5:59
  • This wouldn't be my first approach unless you need sendRawTransaction() for a specific reason. Commented Apr 2, 2018 at 15:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.