stellar-suite
stellar-suite is a JS library to handle stellar easily and usefully. It wraps js-stellar-sdk within. Payment and multisig transactions tend to be complicated JS code, but you can implement them easily by using stellar-suite.
MemoText can be added to a transaction, but the limit 28-byte
. This limit is cleared by working with Ethereum SWAM.
How to install
npm install stellar-suite
The difference development(test) test and production enviroment
development
-
Node.js setting
-
Build command for Built in HTML JS
npm run build -
js file for Built in HTML JS
dist/browser/stellar-suite-dev.js -
Stellar Network is Testnet
-
Etereum Swarm is Mainnet (Because swarm is only mainnet)
production
-
Node.js setting
NODE_ENV=production appjs -
Build command for Built in HTML JS
npm run build.prd -
js file for Built in HTML JS
dist/browser/stellar-suite.js -
Stellar Network is Mainnet
-
Etereum Swarm is Mainnet (Because swarm is only mainnet)
Usage
See src/__test__/*.test.ts
for more information.
Node.js, ES6, Built in HTML
- Node.js
const Account Token Payment Multisig Storage = ;
- ES6
;
- Built in HTML(notice: development is stellar-suite-dev.js)
Modules description
- Account -
Account.create()()
- create account
Account.createTestnet()
- create account for testnet
Account'optional params'
optional param | description |
---|---|
memo(Memo) | MemoType Object |
feeSource | for delegate account when want use feeBump function |
feeMultiplication | default=100. 100 * feeMultiplication |
timeout | set transaction timeout |
development
const Account = ; async const res = await Account; console;; /* response{ pubkey: 'GDCVRRVJVSM7GRKTENFQUGNZA6KPRHP7Q6KXA2P7CCACKA5XMYU4PW2F', secret: 'SCBIJIGN2RLFTZQ52PRA3GRG2GHJVDTWTWIRNA7FG5BMGJSCZ546L2KQ'}*/
production
const Account = ; const creatorSec = 'SD4WH2AE5EBE72K4BIX5GLFVASV45HKRIA5MXVDJ7MNPMMXCGIJZX5SN'; async const res = await Account; console;; /* response{ pubkey: 'GDCVRRVJVSM7GRKTENFQUGNZA6KPRHP7Q6KXA2P7CCACKA5XMYU4PW2F', secret: 'SCBIJIGN2RLFTZQ52PRA3GRG2GHJVDTWTWIRNA7FG5BMGJSCZ546L2KQ'}*/
- All set params that must param and optional param
const Account Memo } = ; const createtor = pubkey: 'GBFCIBLNLSSIM4L662UTIVSMF2CDGM3U7VRMM7D6ECZAKQRSPDRIYKZW' secret: 'SDSIMAPJJC3K4EODTIZGQEKLKSIR2YE2R73V77X6LWVDRLJ5W73EFKW2'; const feeSource = pubkey: 'GAOLT2JOFLPGVMHI56F6D6UIFJROTZ3O47APWBR3JNOYKXFCZ5TL2QDG' secret: 'SCNFMAJ236JZSPFFTKTZCEDWXCKWB62A36PWSYKG7DZCQJJZ3OBOOYD6'; async { const mustParams = secret: createtorsecret startingBalance: '100' const optinalParams = memo: Memotext'Optional Params' feeSource: feeSourcesecret feeMultiplication: 2 timeout: 30 const res = await Account optinalParams ; console;}; /* response { pubkey: 'GB4RN5TOY25BLJTFRU72WG6W65MGEDA6L3VYO5VCRD2B7ZZK76Y7BHQB', secret: 'SDMN5XZ55XO4ODOS37HKCKTMYA57OXT3YF777TATNCP5RCQ4JYOSCKW5'} */
Account.getBalance()
- Get balance(xlm, token) from target address. response is two types.
const Account = ; const pubkey = 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG'; async const res = await Account; console;; /* response{ raw: '9999.9980200', float: '9999.99802' }*/
- Token -
Token.create()
- create stellar token(official name
asset
)
const Token = ; const issuerPubkey = 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG';const tokenName = 'TESTTOKEN'; const res = Token;console; /* responseAsset { code: 'TESTTOKEN', issuer: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG'}*/
Token.trustline()
- trustline need to receive token by receiver
Token'optional params'
optional param | description |
---|---|
memo(Memo) | MemoType Object |
feeSource | for delegate account when want use feeBump function |
feeMultiplication | default=100. 100 * feeMultiplication |
timeout | set transaction timeout |
const Token = ; const issuerPubkey = 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG';const receiverSecret = 'SAMTOLCOEJYAD5JUKP2XUVMGJ3QZ77E26T64PMGXDXLAYX5AQN7CFGTR';const tokenName = 'TESTTOKEN'; async const token = Token; const res = await Token; console;; /* response c176fc1c71dd93c95fd49aef841410ed6eec3dc8937ea13202eb2241a919871c */
Payment
Payment.send()
- send XLM or token
Payment'optional params'
optional param | description |
---|---|
memo(Memo) | MemoType Object |
feeSource | for delegate account when want use feeBump function |
feeMultiplication | default=100. 100 * feeMultiplication |
timeout | set transaction timeout |
- send 1 XLM to receiver address
const Payment = ; const senderSecret = 'SCP5L3JUL4YP62BCUAXY3YXOIRLP3VYRXETANE53QSHKB6D2AMTY52K2';const receiverPubkey = 'GBFXT3XP46G4PNMYM67IN5TC76ZVGBZVV2YTRP23D2IMBXAL2HAWGRO6'; async { const amount = '1'; const res = await Payment; console;}; /* response b3da4cfb11cc918637f2fb4fc05ffda97b6b3cb13e1d44ca5531926d84d77e7e */
- send 1 token(asset) to receiver address
const Token Payment } = ; const issuer = pubkey: 'GBKRTWUPAIABKFIK3FWZYOR2TXM5SHD4NUV225AAOFCV2HTWVEBUDUAC' secret: 'SCP5L3JUL4YP62BCUAXY3YXOIRLP3VYRXETANE53QSHKB6D2AMTY52K2'; const receiver = pubkey: 'GA62CTAT6MCN5BPULVHCF5R44HO4V6M2JPXLGL55DRXNWS2TWVICOOC4' secret: 'SCQSPQESX2TFHOWJV4AF4FBFZVOC4X5JFR6VOJZ2L4K6YSW3XRVLTUAU'; async { const token = Token; await Token; const amount = '1'; const res = await Payment; console;}; /* response c37ee2b833350e4535085061934f797f3c5497a6156618c6f29ea68789fa7f1f */
- Multisig -
Multisig.set()
- set multi signature
Multisig'optional params'
optional param | description |
---|---|
memo(Memo) | MemoType Object |
feeSource | for delegate account when want use feeBump function |
feeMultiplication | default=100. 100 * feeMultiplication |
timeout | set transaction timeout |
- Set multiple signers in a target address
const Multisig } = ; const signer = pubkey: 'GBKRTWUPAIABKFIK3FWZYOR2TXM5SHD4NUV225AAOFCV2HTWVEBUDUAC' secret: 'SCP5L3JUL4YP62BCUAXY3YXOIRLP3VYRXETANE53QSHKB6D2AMTY52K2'; const signer2 = pubkey: 'GB4UYUVCYSAD73QHSPOK3HP3TFIJFE4VWCBMRFQSQDFXGAA4ZXPQYH4F' secret: 'SA67M7KTRTPMGWPHX34W3PA5LWTYJXNGFZUYPJS7MV5WZR5V5EAGURST'; const target = pubkey: 'GA62CTAT6MCN5BPULVHCF5R44HO4V6M2JPXLGL55DRXNWS2TWVICOOC4' secret: 'SCQSPQESX2TFHOWJV4AF4FBFZVOC4X5JFR6VOJZ2L4K6YSW3XRVLTUAU'; async { const res = await Multisig; console;}; /* resposne cacb5986cfdab2b2d7beb3b279da7bdfc0ac43c174356868b49d8f92c211d45c */
- Memo -
Memo.text(), Memo.id(), Memo.hash(), Memo.return()
const Memo } = ; const res = Memotext'0';console; /* resposne Memo { _type: 'text', _value: '0000000000000000000000000000' } */
Memo.Swarm.setText()
- In stellar specific, MemoText is 28kbyte limit. this library internal use Ethereum Swarm, So stored over 28kbyte string.
const Memo } = ; const data = 'In a more restrained appearance, President Trump depicted Joseph R. Biden Jr. as an ineffectual Washington insider. Mr. Biden accused the president of heartlessness for separating migrant families and inflaming racial tensions. by New York Times(23/10/20)';const res = await MemoSwarm;console; /* response Memo { _type: 'hash', _value: <Buffer 43 1d eb 15 22 07 0a 1c dd 0e e4 8d 7f c2 15 3b 49 c5 4f 0a 36 31 c8 7e 1f d6 72 6b de b6 d3 0a>} */
Memo.Swarm.getText()
- To Get stored data from swarm, Use encoded memo data in transaction and set in Memo.Swarm.setText('encoded data')
const Memo } = ; async { const memoHash = 'Qs5GwukTIsifv+X23AaoRqDhK9VCSnzzsqPpae0Enns='; const res = await MemoSwarm; console;}; /* response Btesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest */
Transaction
Transaction.estimatedFee()
- Can get estimate fee price
const Transaction } = ; async { const res = await Transaction; console;}; /* response 100 */
Transaction.feeStats()
- fee history information
const Transaction } = ; async { const res = await Transaction; console;}; /* response { last_ledger: '77168', last_ledger_base_fee: '100', ledger_capacity_usage: '0', fee_charged: { max: '100', min: '100', mode: '100', p10: '100', p20: '100', p30: '100', p40: '100', p50: '100', p60: '100', p70: '100', p80: '100', p90: '100', p95: '100', p99: '100' }, max_fee: { max: '100', min: '100', mode: '100', p10: '100', p20: '100', p30: '100', p40: '100', p50: '100', p60: '100', p70: '100', p80: '100', p90: '100', p95: '100', p99: '100' }} */
Transaction.serverTimeout()
- Can get unix timestamp + param value(second) in Horizon server
const Transaction } = ; async { const res = await Transaction; console;}; /* response { minTime: 0, maxTime: 1604283380 } */
Transaction.get()
- Get transaction datas. currently, only get account base
const Transaction } = ; const pubkey = 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG'; Transaction; /* response { source: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG', fee: '100', hash: '88a34344465b43abbc20ce3201df41a2129d88b94f3243179e3afad1f3ebcebc', createdAt: '2020-11-02T02:40:37Z', operations: [ { source: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG', type: 'payment', destination: 'GBP3XOFYC6TWUIRZAB7MB6MTUZBCREAYB4E7XKE3OWDP75VU5JB74ZF6', asset: [Asset], amount: '100000.0000000' } ], memo: { type: 'none', value: null }, network: 'Test SDF Network ; September 2015', successful: true, feeSource: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG'} */
Transaction.stream()
- Using stream protocol(server sent event),get transaction datas . currently, only get account base.
runtime environment is HTML.
Transaction'optional params'
optional param | description |
---|---|
cursor | payments happening starting position. default: 'now' |
order | ASC or DESC. default: 'ASC' |
limit | display limit count. default: '50', max: '200' |
/* response { source: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG', fee: '100', hash: '88a34344465b43abbc20ce3201df41a2129d88b94f3243179e3afad1f3ebcebc', createdAt: '2020-11-02T02:40:37Z', operations: [ { source: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG', type: 'payment', destination: 'GBP3XOFYC6TWUIRZAB7MB6MTUZBCREAYB4E7XKE3OWDP75VU5JB74ZF6', asset: [Asset], amount: '100000.0000000' } ], memo: { type: 'none', value: null }, network: 'Test SDF Network ; September 2015', successful: true, feeSource: 'GCKFBEIYV2U22IO2BJ4KVJOIP7XPWQGQFKKWXR6DOSJBV7STMAQSMTGG'} */
Examples
-
look at source code: examples/
-
Usage Node.JS example
node examples/nodejsjs
- Usage Browser example
chrome examples/browserhtml