Skip to content

Instantly share code, notes, and snippets.

@gimre-xymcity
Last active July 29, 2023 02:51
Show Gist options
  • Save gimre-xymcity/7965a83745ae62c9de1abefa0d9e92e3 to your computer and use it in GitHub Desktop.
Save gimre-xymcity/7965a83745ae62c9de1abefa0d9e92e3 to your computer and use it in GitHub Desktop.
import symbolSdk from "/path/to/symbolsdk/javascript/src/index.js";
const facade = new symbolSdk.facade.SymbolFacade("testnet");
type PrivateKey = InstanceType<typeof symbolSdk.PrivateKey>;
const privateKey: PrivateKey = symbolSdk.PrivateKey.random();
/*
const privateKey: PrivateKey = new symbolSdk.PrivateKey(
"677035391CD3701293D385F037BA32796252BB7CE180B00B582DD9B20AAAD7F0"
);
*/
console.log(`private key: ${privateKey.toString()}`);
type KeyPair = InstanceType<typeof symbolSdk.symbol.KeyPair>;
const keyPair: KeyPair = new symbolSdk.symbol.KeyPair(privateKey);
console.log(` public key: ${keyPair.publicKey.toString()}`);
const transaction = facade.transactionFactory.create({
type: "transfer_transaction_v1",
signerPublicKey: keyPair.publicKey.toString(),
fee: 1000000n,
deadline: 41998024783n,
recipientAddress: "TCHBDENCLKEBILBPWP3JPB2XNY64OE7PYHHE32I",
mosaics: [{ mosaicId: 0x7cdf3b117a3c40ccn, amount: 1000000n }],
});
type Signature = InstanceType<typeof symbolSdk.Signature>;
const signature: Signature = facade.signTransaction(keyPair, transaction);
console.log(` signature: ${signature.toString()}`);
const jsonPayload: string =
Object.getPrototypeOf(facade.transactionFactory).constructor.attachSignature(
transaction,
signature
);
console.log("json payload:");
console.log(jsonPayload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment