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 generateSignRequest({
uuid,
signData,
dataType,
path,
xfp,
chainId,
address,
origin,
}: {
uuid: string;
signData: string;
dataType: EthDataType;
path: string;
xfp: string;
chainId: number;
address?: string;
origin?: string;
}): UR;
static parseSignature(ur: UR): Record<string, any>;
}
generateSignRequest
static generateSignRequest({
uuid,
signData,
dataType,
path,
xfp,
chainId,
address,
origin,
}: {
uuid: string;
signData: string;
dataType: EthDataType;
path: string;
xfp: string;
chainId: number;
address?: string;
origin?: string;
}): UR;
Input parameters
-
uuid:
StringrequiredRepresenting the unique ID of a transaction -
signData:
StringrequiredUnsigned-transaction data, it's RLP-encoded hex for a EVM transaction -
dataType:
EthDataTyperequiredTransaction type defined by ethereum community, details see below -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
xfp:
StringrequiredMasterFingerprint, used as a unique wallet ID -
chainId:
StringrequiredChainId -
address:
StringoptionalTo address of transaction -
origin:
StringoptionalNotes 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 parseSignature(ur: UR): Record<string, any>;
Returns
-
uuid:
Uint8Listtransaction ID. -
signature:
Stringsignature of transaction. -
origin:
Stringusually "GsWallet".
Example
Construct transaction && Parse signature
import { GsWalletEthereumSDK, EthDataType } from "gs-ur-js"
export const Ethereum = () => {
const [isScanning, setIsScanning] = useState(false);
const ethSignRequest = {
uuid: "6c3633c0-02c0-4313-9cd7-e25f4f296729",
signData: "337B718878426CA568BA103A5048A8D920945CE651C0A5360A79DA7E872E672D46C224866FEAF80F3D948682CCF31B683C1ACC29FA7D9BF6527BF627F545692A00",
dataType: EthDataType.typedTransaction,,
path: "m/44'/60'/0'/0/0",
xfp: "F23F9FD2",
chainId: 1,
origin: "GsWallet"
};
const ur = GsWalletEthereumSDK.generateSignRequest(ethSignRequest);
const onSucceed = ({type, cbor}) => {
const signature = GsWalletEthereumSDK.parseSignature(new UR(Buffer.from(cbor, "hex"), type))
console.log("ethSignature: ", signature);
setIsScanning(false);
}
const onError = (errorMessage) => {
console.log("error: ",errorMessage);
setIsScanning(false);
}
return (
isScanning
? <AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.ETH_SIGNATURE]}
options={{
width: 400,
height: 300
}}
/>
: (
<>
<AnimatedQRCode
type={ur.type}
cbor={ur.cbor.toString("hex")}
options={{
capacity: 200,
interval: 300
}}
/>
<button onClick={() => { setIsScanning(true) }}>Scan GsWallet</button>
</>
)
)
}
// ethSignature: {
// "uuid": [147,240,116,80,141,26,17,239,151,24,207,200,186,0,173,219],
// "signature":"ad8d6c6047bcde2533f532775723acdf476de661bbd1f873971a59f0e735cf520f3266ef4bc8e8627e4dbf62a424c15ccc3feed076e162b86142d8987cabd56600",
// "origin":"GSWALLET",
// };