Skip to main content

Ethereum

This article describes the process of completing a Ethereum transaction through the SDK.

Support List

Support most EVM-series cryptocurrencies and their tokens.

  • Ethereum
  • Binance Smart Chain
  • Polygon
  • Arbitrum
  • Avalanche
  • Optimism
  • Arbitrum Nova
  • Fantom
  • Zksync_era
  • OKTC
  • Metis
  • Scroll
  • Linea
  • And many other networks...

GsWalletEthereumSDK

The GsWalletEthereumSDK class mainly implements the following functions:

  • Construct EVM transactions.
  • Parse signature information.
class GsWalletEthereumSDK {

static UR generateSignRequest({
String? uuid,
required String signData,
required EthDataType dataType,
required String path,
required String xfp,
required int chainId,
String? address,
String? origin,
});

static Map<String, dynamic> parseSignature(UR ur);

}

generateSignRequest

static UR generateSignRequest({
String? uuid,
required String signData,
required EthDataType dataType,
required String path,
required String xfp,
required int chainId,
String? address,
String? origin,
})

Input parameters

  • uuid: String optional Representing the unique ID of a transaction

  • signData: String required Unsigned-transaction data, it's RLP-encoded hex for a EVM transaction

  • dataType: EthDataType required Transaction type defined by ethereum community, details see below

  • path: String required BIP32 derivation path for from-address of the transaction

  • xfp: String required MasterFingerprint, used as a unique wallet ID

  • chainId: String required ChainId

  • address: String optional To address of transaction

  • origin: String optional Notes for transaction, usually the name of the cryptocurrency wallet

DataType

  • transaction = 1, //Type 0 (Legacy) Transactions.
  • typedData = 2, // For the EIP-712 typed data. Bytes of the json string.
  • personalMessage = 3, // For the personal message signing.
  • typedTransaction = 4 // For the typed transaction, like the EIP-1559 transaction.

parseSignature

static Map<String, dynamic> parseSignature(UR ur);

Returns

  • uuid: Uint8List transaction ID.

  • signature: String signature of transaction.

  • origin: String usually "GsWallet".

Example

Construct transaction

import 'package:gs_ur_dart/gs_ur_dart.dart';

UR ur = GsWalletEthereumSDK.generateSignRequest(
uuid: "6c3633c0-02c0-4313-9cd7-e25f4f296729",
signData:
"337B718878426CA568BA103A5048A8D920945CE651C0A5360A79DA7E872E672D46C224866FEAF80F3D948682CCF31B683C1ACC29FA7D9BF6527BF627F545692A00",
dataType: EthDataType.typedTransaction,
path: "m/44'/60'/0'/0/0",
xfp: "F23F9FD2",
chainId: 1,
origin: "GsWallet");

final UREncoder urEncoder = UREncoder(ur);
String _currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
timer = Timer.periodic(const Duration(milliseconds: 250), (_) {
_currentQR = urEncoder.nextPart();
emit(_AnimatedQRDataState(_currentQR));
});

Parse signature

import 'package:gs_ur_dart/gs_ur_dart.dart';

typedef SuccessCallback = void Function(UR);
final SuccessCallback onSuccess;

final QRViewController controller;

controller.scannedDataStream.listen((event) {
URDecoder urDecoder = URDecoder();
urDecoder.receivePart(event.code);
double progress = urDecoder.getProgress();
if (urDecoder.isComplete()) {
final UR result = urDecoder.resultUR();
if (!succeed) {
onSuccess(result);
succeed = true;
}
}
});

onSuccess(UR ur){
final ethSigned = GsWalletEthereumSDK.parseSignature(ur);
}

// ethSigned: {
// "uuid": [147,240,116,80,141,26,17,239,151,24,207,200,186,0,173,219],
// "signature":"ad8d6c6047bcde2533f532775723acdf476de661bbd1f873971a59f0e735cf520f3266ef4bc8e8627e4dbf62a424c15ccc3feed076e162b86142d8987cabd56600",
// "origin":"GSWALLET",
// };