Skip to main content

Solana

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

Support List

Support most SOL-series cryptocurrencies and their tokens.

  • Solana

GsWalletSolSDK

The GsWalletSolSDK class mainly implements the following functions:

  • Construct SOL transactions.
  • Parse signature information.
class GsWalletSolSDK {

static generateSignRequest({
uuid,
signData,
signType,
path,
xfp,
outputAddress,
contractAddress,
origin,
fee,
}: {
uuid: string;
signData: string;
signType: SignType;
path: string;
xfp: string;
outputAddress?: string;
contractAddress?: string;
origin?: string;
fee?: number;
}): UR

static parseSignature(ur: UR): Record<string, any>;

}

generateSignRequest

static generateSignRequest({
uuid,
signData,
signType,
path,
xfp,
outputAddress,
contractAddress,
origin,
fee,
}: {
uuid: string;
signData: string;
signType: SignType;
path: string;
xfp: string;
outputAddress?: string;
contractAddress?: string;
origin?: string;
fee?: number;
}): UR

Input parameters

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

  • signData: String required Unsigned-transaction data, it's serialized hex for a SOL transaction

  • signType: SignType required Unsigned-message type

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

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

  • outputAddress: String optional Receiving address, it is required if it is a token transaction

  • contractAddress: String optional Contract address, it is required if it is a token transaction

  • origin: String optional Notes for transaction, usually source of the request

  • fee: int optional Transaction fee, minimum unit.

parseSignature

static parseSignature(ur: UR): Record<string, any>;

Returns

  • uuid: Uint8List transaction ID.

  • signature: String signature of transaction.

  • origin: String usually "GsWallet".

Example

Construct transaction && Parse signature

import {GsWalletSolSDK, } from "gs-ur-js";

export const Solana = () => {
const [isScanning, setIsScanning] = useState(false);
const [solSignedData, setsolSignedData] = useState(null);
const ur = GsWalletSolSDK.generateSignRequest(
uuid: "65781260-8d2c-11ef-806b-cf7f7ddae54a",
signData:
"01000203d9aa0cde2dd59caa4e04fe703439abba02d81391adb78dd1e67130e93684951200000000000000000000000000000000000000000000000000000000000000000306466fe5211732ffecadba72c39be7bc8ce5bbc5f7126b2c439b3a40000000d88b1bb92a7e915051f7287e53d1c6a2bd97a7a6c169a6ee00a912f793936e0c03010200000c02000000158d0b020000000002000502400d030002000903801a060000000000",
signType: SignType.transaction,
path: "m/44'/501'/0'/0'",
xfp: "27c3831f",
outputAddress: null,
contractAddress: null,
origin: null,
fee: 100000);

const onSucceed = ({type, cbor}) => {
const solSigned = GsWalletSolSDK.parseSignature(new UR(Buffer.from(cbor, "hex"), type))
setsolSignedData(solSigned);
setIsScanning(false);
console.log("solSigned: ", solSigned);
}
const onError = (errorMessage) => {
setsolSignedData(null);
setIsScanning(false);
console.log("error: ",errorMessage);
}

return (
<div style={{ display: 'flex', alignItems: 'center' }}> {/* Use flexbox for layout */}
{isScanning ? <AnimatedQRScanner handleScan={onSucceed} handleError={onError} urTypes={URType.SolSignature} />: (
<>
<AnimatedQRCode type={ur.type} cbor={ur.cbor.toString("hex")}/>
<button style={{marginLeft: '20px'}} onClick={() => setIsScanning(true)}>Scan GsWallet</button>
{solSignedData && ( // Conditionally render the box
<div style={{
marginLeft: '20px', // Add some spacing
border: '1px solid #ccc',
padding: '10px',
backgroundColor: '#f9f9f9'
}}>
<h3>solSigned Data:</h3>
<pre>{solSignedData}</pre> {/* Display solSigned directly */}
</div>
)}
{solSignedData === null && <div style={{marginLeft: '40px'}}>Waiting for scan...</div>}
</>
)}
</div>
);
}

// solSigned: {
// "uuid": [101,120,18,96,141,44,17,239,128,107,207,127,125,218,229,74],
// "signature":"1cd95cbd3df72efe043ff50da43f03e6fed76a133a62f1b897de9ecc0ecd50e5d9a35ebf0340eb4368ee681b2387db3c053d69e09927e642ef8aa70b3502320b",
// "origin":"GSWALLET",
// };