Atom
This article describes the process of completing a Atom transaction through the SDK.
Support List
Support most COSMOS-series cryptocurrencies.
- Atom
- Kava
- Sei
GsWalletCosmosSDK
The GsWalletCosmosSDK class mainly implements the following functions:
- Construct COSMOS transactions.
- Parse signature information.
class GsWalletCosmosSDK {
static generateSignRequest({
uuid,
signData,
path,
chain,
xfp,
origin,
fee,
}: {
uuid: string;
signData: string;
path: string;
chain: string;
xfp: string;
origin?: string;
fee?: number;
}): UR;
static parseSignature(ur: UR): Record<string, any>;
}
generateSignRequest
static generateSignRequest({
uuid,
signData,
path,
chain,
xfp,
origin,
fee,
}: {
uuid: string;
signData: string;
path: string;
chain: string;
xfp: string;
origin?: string;
fee?: number;
}): UR;
Input parameters
-
uuid:
StringrequiredRepresenting the unique ID of a transaction -
signData:
StringrequiredUnsigned-transaction data, it's serialized hex for a COSMOS transaction -
path:
StringrequiredBIP32 derivation path for from-address of the transaction -
xfp:
StringrequiredMasterFingerprint, used as a unique wallet ID -
chain:
StringrequiredChain name -
origin:
StringoptionalNotes for transaction, usually source of the request -
fee:
intoptionalTransaction fee, minimum unit.
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 { GsWalletCosmosSDK } from "gs-ur-js";
export const Cosmos = () => {
const [isScanning, setIsScanning] = useState(false);
const [atomSignedData, setatomSignedData] = useState(null);
const ur = GsWalletCosmosSDK.generateSignRequest(
uuid: "cf727aa0-8d24-11ef-90ac-6dae386eaee6",
signData:
"0aa1010a8f010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126f0a2d636f736d6f7331373074666d7a3463323375336177746637346b6535746e676b656d6a6d3561617236376c6d70122d636f736d6f7331373074666d7a3463323375336177746637346b6535746e676b656d6a6d3561617236376c6d701a0f0a057561746f6d1206393738383030120d687562205468652067686f737412670a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21030edaa670d688c4ab1c9a8272c88fe62ec15be8c08903c43929e7be666c44953612040a020801180112130a0d0a057561746f6d12043139333610efdc041a0b636f736d6f736875622d3420d7917d",
path: "m/44'/118'/0'/0/0",
xfp: "27c3831f",
chain: "Cosmos_Hub",
origin: null,
fee: 2000);
const onSucceed = ({ type, cbor }) => {
const atomSigned = GsWalletCosmosSDK.parseSignature(new UR(Buffer.from(cbor, "hex"), type))
console.log("atomSigned: ", atomSigned);
setatomSignedData(atomSigned);
setIsScanning(false);
}
const onError = (errorMessage) => {
console.log("error: ", errorMessage);
setatomSignedData(null);
setIsScanning(false);
}
return (
<div style={{ display: 'flex', alignItems: 'center' }}> {/* Use flexbox for layout */}
{isScanning
? <AnimatedQRScanner
handleScan={onSucceed}
handleError={onError}
urTypes={[URType.CosmosSignature]}
options={{
width: 400,
height: 300
}}
/>
: (
<>
<AnimatedQRCode type={ur.type} cbor={ur.cbor.toString("hex")} />
<button style={{ marginLeft: '20px' }} onClick={() => setIsScanning(true)}>Scan GsWallet</button>
{atomSignedData && ( // Conditionally render the box
<div style={{
marginLeft: '20px', // Add some spacing
border: '1px solid #ccc',
padding: '10px',
backgroundColor: '#f9f9f9'
}}>
<h3>atomSigned Data:</h3>
<pre>{atomSignedData}</pre> {/* Display atomSigned directly */}
</div>
)}
{atomSignedData === null && <div style={{ marginLeft: '40px' }}>Waiting for scan...</div>}
</>
)}
</div>
);
}
// atomSigned: {
// "uuid": [207,114,122,160,141,36,17,239,144,172,109,174,56,110,174,230],
// "signature":"e6de945a91c14458b6a21fff2f3035882379e1da281ae1894d81fa525ab7b0e015ae216c7fe528d669a5b303aa3a61e79f0b9f54b18aa2739dfd8fc6988c8f10",
// "origin":"GSWALLET",
// };