weishirongzhen / flutter_trust_wallet_core

MIT License
88 stars 33 forks source link

Add more examples #27

Open sylvestrevgen opened 2 years ago

sylvestrevgen commented 2 years ago

Hello. Thank you for this plugin, it is very great and useful. Can you add more examples for different cois and ethereum transaction example, please?

mahdibagjani commented 2 years ago

I need too. add an ethereum example please.

weishirongzhen commented 2 years ago

Will do, but it will not be so fast, currently I'm using this lib for my product, a lots api may have breaking changes due to requirements, I'll add more eth example in few days. Btw the best tutorial please refer to trust wallet core official test case.

sylvestrevgen commented 2 years ago

Thank you so much. Waiting for that.

sylvestrevgen commented 2 years ago

Hello. Any updates about ethereum transaction example?

edTheGuy00 commented 2 years ago

@sylvestrevgen @mahdibagjani The official tests are a really good reference, I got basic ETH transactions signed and submitted to network like this:

Note: need to convert hex into byte arrays for the protobuf messages with the convert package hex.decode(myHex)


final input = SigningInput(
  privateKey: privateKey.data(),
  chainId: hex.decode('0539'),  // 1337 for ganache
  nonce: hex.decode('01'),
  gasPrice: hex.decode('04a817c800'), // 20000000000
  gasLimit: hex.decode('5208'), // 21000
  toAddress: receiverAddress,
  transaction: Transaction(
    transfer: Transaction_Transfer(
      amount: hex.decode('0de0b6b3a7640000'), // 1 ETH
    ),
  ),
);

final signed = AnySigner.sign(
  input.writeToBuffer(),
  TWCoinType.TWCoinTypeEthereum,
);

  final output = SigningOutput.fromBuffer(signed);

// Now you can submit the encoded output to the network
output.encoded
jalchr commented 2 years ago

@edTheGuy00 perfect... Any tips how are you submitting this to the network using Flutter ? Are you using any third party endpoints or APIs?

Appreciate any feedback