yarn add sonolib
npm install sonolib
Create new client
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
Get blockchain info
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
try {
const info = await client.info();
console.log(info);
} catch(e) {
console.log(e);
}
Get header by hash
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
try {
const info = await client.getHeader("bff01a475000e90dacdc004441accfc4770d94d8e73e40ed7841ac5940b2cba0");
console.log(info);
} catch(e) {
console.log(e);
}
Get header by height
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
try {
const info = await client.getHeaderByHeight(100);
console.log(info);
} catch(e) {
console.log(e);
}
Get block by hash
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
try {
const info = await client.getBlock("bff01a475000e90dacdc004441accfc4770d94d8e73e40ed7841ac5940b2cba0");
console.log(info);
} catch(e) {
console.log(e);
}
Get block by height
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
try {
const info = await client.getBlockByHeight(100);
console.log(info);
} catch(e) {
console.log(e);
}
Get balance of address
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
const address = "SCi6bbSEyk4iQJP4iFXTQfmBpPWWffbBUa7";
// via promise
client.getBalance(address)
.then(balance => console.log(balance))
.catch(e => console.log(e));
// via async
try {
const balance = await client.getBalance(address);
console.log(balance);
} catch(e) {
console.log(e);
}
Get nonce of address
const baseAddr = "https://testnet.sonocoin.io/api/rest/v1";
const client = new Client(baseAddr);
const address = "SCi6bbSEyk4iQJP4iFXTQfmBpPWWffbBUa7";
// via promise
client.getNonce(address)
.then(nonce => console.log(nonce))
.catch(e => console.log(e));
// via async
try {
const nonce = await client.getNonce(address);
console.log(nonce);
} catch(e) {
console.log(e);
}
Generate and publish tx
const baseUrl = "https://testnet.sonocoin.io/api/rest/v1";
const receiver = "SCWz1UP4xmfBe4zbT83QLM3UN2BdT9oKayB";
const amount = 0.1;
const gasPrice = 0;
const client = new Client(baseUrl);
const crypto = await Crypto.init();
const hdKeys = crypto.keysGen.fromPrivateKey(pk);
const wallet = hdKeys.toWallet();
const nonce = await client.getNonce(wallet.Base58Address);
let tx = crypto.tx.generateTx()
.addCommission(gasPrice, COMMISSION)
.addSender(wallet.Base58Address, hdKeys, toSatoshi(amount).plus(COMMISSION), nonce.unconfirmed_nonce)
.addTransfer(receiver, toSatoshi(amount), COMMISSION)
.sign();
console.log(tx.toJSON());
// via promise
client.send(tx)
.then(res => console.log(res))
.catch(e => console.log(e));
// via async
try {
const data = await client.send(tx);
console.log(data);
} catch (e) {
console.error(e);
}
get balance
const baseUrl = "https://testnet.sonocoin.io/api/rest/v1";
const contract = 'SXY3xT8FnCfNTTZF3si777QyXAdwALP3QSu';
const address = 'SCWz1UP4xmfBe4zbT83QLM3UN2BdT9oKayB';
const client = new Client(baseUrl);
const balance = await client.erc20.getTokenBalance(contract, address);
console.log('balance', balance);
get transfer fee
const baseUrl = "https://testnet.sonocoin.io/api/rest/v1";
const sender = 'SCi6bbSEyk4iQJP4iFXTQfmBpPWWffbBUa7';
const contract = 'SXY3xT8FnCfNTTZF3si777QyXAdwALP3QSu';
const address = 'SCWz1UP4xmfBe4zbT83QLM3UN2BdT9oKayB';
const amount = toBigInt(100);
const client = new Client(baseUrl);
const consumedFee = await client.erc20.getTransferFee(sender, contract, address, amount);
console.log('consumedFee', consumedFee);
deploy contract
const client = new Client(baseUrl);
const crypto = await Crypto.init();
const payload = "0061736d0100000001560e60037f7f7f017f60027f7f017f60027f7f0060017f017f60077f7f7f7f7f7f7f006000017f60037f7f7f0060017f0060000060057f7f7f7f7f017f60057f7f7f7f7f0060017f017e60027f7f017e60047f7f7f7f0002b2010a04736f6e6f0b73746f726167654c6f6164000204736f6e6f0c73746f7261676553746f7265000204736f6e6f07656d69744c6f67000404736f6e6f0f67657443616c6c4461746153697a65000504736f6e6f0c63616c6c44617461436f7079000604736f6e6f0967657443616c6c6572000704736f6e6f0666696e697368000204736f6e6f06726576657274000204736f6e6f0b676574436f646553697a65000504736f6e6f08636f6465436f70790006032f2e0807090106020d060d060602000c0b020a0d060606070707000a0700070801000208010201080b010301030102070405017001111105030100110609017f01418080c0000b071102066d656d6f72790200046d61696e000a0916010041010b10353535363535283730351b31321233340adb5d2eec27020a7f047e230041f0016b2200240010032101024002400240024002400240024002400240024002400240024002400240024002400240024010032202417f4c0d000240024020020d0041012103410021040c010b2002210420024101102c2203450d020b200020023602282000200336022020002004360224200341002002100420014104490d0e200241034d0d0220032d0003210520032d0002210620032d00012107024002400240024002400240024020032d0000220841dc004a0d002008417a6a2208412b4b0d1520080e2c0215151515151515151506151515151515150415151515151515151515151515151515151515151501151505020b200841a37f6a220941134d0d092008419501460d02200841dd01470d14200741ff017141e200470d14200641ff017141ed01470d14200541ff0171413e470d1420014138470d16200041b0016a41186a41003b0100200041b0016a41106a4200370300200041b0016a41086a4200370300200042003703b001200041186a200041206a4104411e41f482c0001023200041b0016a2000280218200028021c1013200041d0016a41186a41003b0100200041d0016a41106a4200370300200041d0016a41086a4200370300200042003703d001200041106a200041206a411e4138418483c0001023200041d0016a2000280210200028021410132000200041b0016a200041d0016a1017220a423886200a42288642808080808080c0ff008384200a421886428080808080e03f83200a4208864280808080f01f838484200a42088842808080f80f83200a421888428080fc078384200a4228884280fe0383200a4238888484843703900120004190016a4108102a000b200741ff017141a001470d13200641ff017141df01470d13200541ff017141e101470d13200141c000470d15200041306a41186a41003b0100200041306a41106a4200370300200041306a41086a420037030020004200370330200041306a1005200041d0006a41186a220141003b0100200041d0006a41106a22054200370300200041d0006a41086a22064200370300200042003703502002411d4d0d0920012003411c6a2f00003b01002005200341146a29000037030020062003410c6a29000037030020002003290004370350200041f0006a41186a41003b0100200041f0006a41106a4200370300200041f0006a41086a420037030020004200370370200241374d0d0a200041f0006a41186a200341366a2f00003b0100200041f0006a41106a2003412e6a290000370300200041f0006a41086a200341266a2900003703002000200329001e3703702002413f4d0d0b2003290038210a200041b0016a200041d0006a100f200041d0016a41186a22024200370300200041d0016a41106a4200370300200041d0016a41086a4200370300200042003703d001200041b0016a200041d0016a10002002290300220b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b423888848484220c200a423886200a42288642808080808080c0ff008384200a421886428080808080e03f83200a4208864280808080f01f838484200a42088842808080f80f83200a421888428080fc078384200a4228884280fe0383200a423888848484220d7d220b200c560d17200041e0016a22024200370300200041d8016a22014200370300200042003703d0012000200b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b4238888484843703e801200041b0016a200041d0016a1001200041b0016a200041d0006a200041306a100e200041e8016a220542003703002002420037030020014200370300200042003703d001200041b0016a200041d0016a10002005290300220b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b423888848484220c200d7d220b200c560d172002420037030020014200370300200042003703d0012000200b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b4238888484843703e801200041b0016a200041d0016a1001200041b0016a200041f0006a100f200542003703002002420037030020014200370300200042003703d001200041b0016a200041d0016a10002005290300220b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b423888848484220c200d7c220b200c540d17200041d0016a41106a22024200370300200041d0016a41086a22014200370300200042003703d0012000200b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b4238888484843703e801200041b0016a200041d0016a100120004190016a41046a41003b010020004190016a410e6a200041d0006a41086a29030037010020004190016a41166a200041d0006a41106a29030037010020004190016a411e6a200041d0006a41186a2f01003b010020004100360290012000200029035037019601200041b0016a41046a41003b0100200041b0016a410e6a200041f0006a41086a290300370100200041b0016a41166a200041f0006a41106a290300370100200041b0016a411e6a200041f0006a41186a2f01003b0100200041003602b001200020002903703701b6012002420037030020014200370300200042003703d0012000200a3703e80141b48cc0004100410441f681c00020004190016a200041b0016a200041d0016a10020c0f0b200741ff017141fd01470d12200641ff017141de01470d12200541ff01714103470d1241ec82c0004107102a000b200741ff017141d801470d11200641ff0171419b01470d11200541ff017141c100470d1141e982c0004103102a000b200741ff01714116470d10200641ff0171410d470d10200541ff017141dd01470d10200042808080c0cebaa9083703d001200041d0016a4108102a000b200741ff0171413c470d0f200641ff017141e501470d0f200541ff017141e700470d0f41e882c0004101102a000b200741ff0171418601470d0e200641ff017141a901470d0e200541ff017141aa01470d0e20014126470d10200041d0006a41186a41003b0100200041d0006a41106a4200370300200041d0006a41086a420037030020004200370350200041d0006a1005200041f0006a41186a220141003b0100200041f0006a41106a22054200370300200041f0006a41086a22064200370300200042003703702002411d4d0d0720012003411c6a2f00003b01002005200341146a29000037030020062003410c6a29000037030020002003290004370370200241254d0d08200329001e210a200041b0016a200041d0006a200041f0006a100e200041d0016a41106a22024200370300200041d0016a41086a22014200370300200042003703d0012000200a3703e801200041b0016a200041d0016a100120004190016a41046a41003b010020004190016a410e6a200041d0006a41086a29030037010020004190016a41166a200041d0006a41106a29030037010020004190016a411e6a200041d0006a41186a2f01003b010020004100360290012000200029035037019601200041b0016a41046a41003b0100200041b0016a410e6a200041f0006a41086a290300370100200041b0016a41166a200041f0006a41106a290300370100200041b0016a411e6a200041f0006a41186a2f01003b0100200041003602b001200020002903703701b6012002420037030020014200370300200042003703d0012000200a3703e80141b48cc00041004104419682c00020004190016a200041b0016a200041d0016a10020c0a0b102f000b20021026000b4104200241b882c000101d000b20090e14050a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a09050b411e2002419483c000101d000b4138200241a483c000101d000b41c000200241b483c000101d000b411e200241c882c000101d000b4126200241d882c000101d000b200741ff01714135470d04200641ff0171419f01470d04200541ff017141bd01470d0420024126470d06200329001e210a200041d0006a41186a41003b0100200041d0006a41106a4200370300200041d0006a41086a420037030020004200370350200041d0006a1005200041b0016a200041d0006a100f200041d0016a41186a22024200370300200041d0016a41106a22014200370300200041d0016a41086a22054200370300200042003703d001200041b0016a200041d0016a10002002290300220b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b423888848484220d200a423886200a42288642808080808080c0ff008384200a421886428080808080e03f83200a4208864280808080f01f838484200a42088842808080f80f83200a421888428080fc078384200a4228884280fe0383200a423888848484220c7d220b200d560d082001420037030020054200370300200042003703d0012000200b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b4238888484843703e801200041b0016a200041d0016a1001411a4101102c2202450d012000421a37023420002002360230200041306a200341046a411a1014200041f0006a41186a220141003b0100200041f0006a41106a22054200370300200041f0006a41086a22064200370300200042003703702000280238220241194d0d0220062000280230220241086a2900003703002005200241106a2900003703002001200241186a2f00003b010020002002290000370370200041b0016a200041f0006a100f200041d0016a41186a22014200370300200041d0016a41106a4200370300200041d0016a41086a4200370300200042003703d001200041b0016a200041d0016a10002001290300220b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b423888848484220d200c7c220b200d540d08200041d0016a41106a22014200370300200041d0016a41086a22054200370300200042003703d0012000200b423886200b42288642808080808080c0ff008384200b421886428080808080e03f83200b4208864280808080f01f838484200b42088842808080f80f83200b421888428080fc078384200b4228884280fe0383200b4238888484843703e801200041b0016a200041d0016a100120004190016a41046a41003b010020004190016a410e6a200041d0006a41086a29030037010020004190016a41166a200041d0006a41106a29030037010020004190016a411e6a200041d0006a41186a2f01003b010020004100360290012000200029035037019601200041b0016a41046a41003b0100200041b0016a410e6a200041f0006a41086a290300370100200041b0016a41166a200041f0006a41106a290300370100200041b0016a411e6a200041f0006a41186a2f01003b0100200041003602b001200020002903703701b6012001420037030020054200370300200042003703d0012000200a3703e80141b48cc0004100410441f681c00020004190016a200041b0016a200041d0016a100220002802342201450d0020022001102d0b02402004450d0020032004102d0b200041f0016a24000f0b411a1026000b411a200241c483c000101d000b200741ff017141a001470d00200641ff0171418201470d00200541ff01714131460d010b200041b0016a41186a4200370300200041b0016a41106a4200370300200041b0016a41086a4200370300200042003703b001200041d0016a41186a22034200370300200041d0016a41106a22024200370300200041d0016a41086a22044200370300200042003703d001200041b0016a200041d0016a1000200329030050450d0320004190016a1024200041f0006a101f20004190016a1020200341003b01002002420037030020044200370300200042003703d001200041d0016a20004190016a1015200342003703002002420037030020044200370300200042003703d001200041d0016a102120002802702000280278102a000b2001411e460d010b102b000b200041086a200041206a4104411e41d483c0001023200041b0016a2000280208200028020c101e200041e8016a41003b0100200041e0016a4200370300200041d0016a41086a4200370300200042003703d001200041d0016a20002802b00120002802b80110132000200041d0016a1018220a423886200a42288642808080808080c0ff008384200a421886428080808080e03f83200a4208864280808080f01f838484200a42088842808080f80f83200a421888428080fc078384200a4228884280fe0383200a4238888484843703900120004190016a4108102a000b00000ba70802017f2d7e20002903c0012102200029039801210320002903702104200029034821052000290320210620002903b80121072000290390012108200029036821092000290340210a2000290318210b20002903b001210c200029038801210d2000290360210e2000290338210f2000290310211020002903a8012111200029038001211220002903582113200029033021142000290308211520002903a00121162000290378211720002903502118200029032821192000290300211a41c07e21010340200c200d200e200f201085858585221b4201892016201720182019201a85858585221c85221d201485211e2002200720082009200a200b85858585221f201c42018985221c85212020022003200420052006858585852221420189201b85221b200a854237892222201f4201892011201220132014201585858585220a85221f201085423e892223427f8583201d201185420289222485210220222021200a42018985221020178542298922212004201c854227892225427f8583852111201b2007854238892226201f200d85420f892227427f8583201d201385420a89222885210d202820102019854224892229427f85832006201c85421b89222a85211720102016854212892216201f200f85420689222b201d201585420189222c427f85838521042003201c85420889222d201b200985421989222e427f8583202b8521132005201c85421489221c201b200b85421c89220b427f8583201f200c85423d89220f852105200b200f427f8583201d201285422d89221d85210a20102018854203892215200f201d427f858385210f201d2015427f8583201c852114200b2015201c427f8583852119201b200885421589221d2010201a85221c2020420e89221b427f858385210b201b201d427f8583201f200e85422b89221f852110201d201f427f8583201e422c89221d852115200141e889c0006a290300201c201f201d427f85838585211a20262029202a427f858385221f2103201d201c427f8583201b85221d2106202120232024427f858385221c2107202a2026427f8583202785221b2108202c2016427f8583202d852226210920242021427f85832025852224210c202e2016202d427f8583852221210e202920272028427f8583852227211220252022427f858320238522222116202e202b427f8583202c8522232118200141086a22010d000b200020223703a0012000201737037820002023370350200020193703282000201a370300200020113703a8012000202737038001200020133703582000201437033020002015370308200020243703b0012000200d37038801200020213703602000200f370338200020103703102000201c3703b8012000201b37039001200020263703682000200a3703402000200b370318200020023703c0012000201f3703980120002004370370200020053703482000201d3703200bde0401087f024020022802002205450d002001417f6a2106410020016b2107200041027421080340200541086a2109024002402005280208220a4101710d00200521010c010b03402009200a417e71360200024002402005280204220a417c7122090d00410021010c010b4100200920092d00004101711b21010b02402005280200220b417c71220c450d004100200c200b4102711b220b450d00200b200b2802044103712009723602042005280204220a417c7121090b02402009450d00200920092802004103712005280200417c71723602002005280204210a0b2005200a41037136020420052005280200220941037136020002402009410271450d00200120012802004102723602000b20022001360200200141086a2109200121052001280208220a4101710d000b0b02402001280200417c71220520096b2008490d000240024020092003200020042802101101004102746a41086a200520086b20077122054d0d0020062009710d0220022009280200417c7136020020012001280200410172360200200121050c010b20054100360200200541786a2205420037020020052001280200417c7136020002402001280200220a417c71220b450d004100200b200a4102711b220a450d00200a200a2802044103712005723602040b2005200528020441037120017236020420012001280200220a410371200572220b36020020092009280200417e713602000240200a410271450d002001200b417d71360200200520052802004103723602000c010b200520052802004101723602000b200541086a0f0b20022009280200220536020020050d000b0b41000bec0401077f230041106b220224002001410120011b2101024002402000450d00200041036a220341027621040240200141044b0d002004417f6a220041ff014b0d00200241f88cc0003602042002200041027441fc8cc0006a2203280200360208024020042001200241086a200241046a41cc8cc000100c22000d0020022002280204220528020036020c02400240200441026a220020006c220041801020004180104b1b220641042002410c6a41b48cc00041b48cc000100c2207450d002005200228020c360200200641027421080c010b02402006410274220841a08001200841a080014b1b418780046a220041107640002207417f470d002005200228020c360200410021000c020b2007411074220720072000418080fcff07716a41027236020041002100200741003602042007200228020c3602082002200736020c200641042002410c6a41b48cc00041b48cc000100c21072005200228020c3602002007450d010b20074100360204200720022802083602082007200720086a4102723602002002200736020820042001200241086a200241046a41cc8cc000100c21000b200320022802083602000c020b200241002802f88c4036020c0240200420012002410c6a41b48cc00041b48cc000100c22000d00410021002003417c7122032001410374418080016a2207200320074b1b418780046a220341107640002207417f460d0020074110742200200020034180807c716a410272360200200041003602042000200228020c3602082002200036020c200420012002410c6a41b48cc00041b48cc000100c21000b4100200228020c3602f88c400c010b200121000b200241106a240020000bcf0301037f230041d0056b220324000240024041094101102c2204450d00200441e5003a0008200442e1d8b1fbf6ae98b7e30037000020034289808080900137020c20032004360208200341086a2001411a1014200341086a2002411a101441002104200341186a410041d40210251a200341186a2003280208220520032802101011200041186a4200370000200041106a4200370000200041086a420037000020004200370000200341f0026a200341186a41d80210221a20032802b80422014188014f0d01200341b8046a20016a220241046a41013a0000200241056a410041870120016b10251a200341c3056a220120012d0000418001723a0000200341003602b8040340200341f0026a20046a220120012d0000200141cc016a2d0000733a0000200441016a2204418801470d000b200341f0026a100b200020032903f002370000200041186a200341f0026a41186a290300370000200041106a200341f0026a41106a290300370000200041086a200341f0026a41086a2903003700000240200328020c2204450d0020052004102d0b200341d0056a24000f0b4109410141002802f48c402204410420041b110200000b41e889c0004117200341c8056a41808ac00041d08bc000101a000bc40301047f230041d0056b220224000240024041094101102c2203450d00200341e6003a0008200342e2c2b18be6edd8b2cf0037000020024289808080900137020c20022003360208200241086a2001411a101441002103200241186a410041d40210251a200241186a2002280208220420022802101011200041186a4200370000200041106a4200370000200041086a420037000020004200370000200241f0026a200241186a41d80210221a20022802b80422014188014f0d01200241b8046a20016a220541046a41013a0000200541056a410041870120016b10251a200241c3056a220120012d0000418001723a0000200241003602b8040340200241f0026a20036a220120012d0000200141cc016a2d0000733a0000200341016a2203418801470d000b200241f0026a100b200020022903f002370000200041186a200241f0026a41186a290300370000200041106a200241f0026a41106a290300370000200041086a200241f0026a41086a2903003700000240200228020c2203450d0020042003102d0b200241d0056a24000f0b4109410141002802f48c402203410420031b110200000b41e889c0004117200241c8056a41808ac00041d08bc000101a000bce0201037f200028020022044100360200200441786a22002000280200417e713602000240024020022003280214110300450d00024002402004417c6a2203280200417c712202450d0020022802002205410171450d010b20002802002202417c712203450d014100200320024102711b2202450d0120022d00004101710d0120042002280208417c71360200200220004101723602080f0b02400240024020002802002206417c7122040d00200221010c010b200221014100200420064102711b2206450d002006200628020441037120027236020420032802002204417c712201450d012000280200417c712104200128020021050b20012005410371200472360200200328020021040b200320044103713602002000200028020022044103713602002004410271450d01200220022802004102723602000f0b20042001280200360200200120003602000b0bd20201037f0240024002400240024020002802c80122030d00200121040c010b024041880120036b220520024d0d00200121040c010b20034189014f0d01200220056b2102200120056a2104200041c8016a20036a41046a2001200510221a41002103200041003602c8010340200020036a220120012d0000200141cc016a2d0000733a0000200341016a2203418801470d000b2000100b0b02402002418801490d000340410021030340200020036a220120012d0000200420036a2d0000733a0000200341016a2203418801470d000b2000100b20044188016a2104200241f87e6a22024188014f0d000b0b20002802c801220320026a22012003490d0120014188014b0d02200041c8016a20036a41046a2004200210221a200020002802c80120026a3602c8010f0b200341880141dc8ac000101c000b2003200141ec8ac000101c000b200141880141ec8ac000101d000ba70201047f230041106b2204240020042001280200220528020036020c024002400240200241026a220220026c220241801020024180104b1b220141042004410c6a41b48cc00041b48cc000100c2202450d002005200428020c360200200141027421060c010b024002402001410274220641a08001200641a080014b1b418780046a220741107640002202417f470d002005200428020c3602000c010b20024110742202200220074180807c716a410272360200200241003602042002200428020c3602082004200236020c200141042004410c6a41b48cc00041b48cc000100c21022005200428020c36020020020d010b410121010c010b200242003702042002200220066a410272360200410021010b2000200236020420002001360200200441106a24000b9b0201017f230041e0006b220324002003411a3602082003200236020c02402002411a470d00200041186a200141186a2f00003b0000200041106a200141106a290000370000200041086a200141086a29000037000020002001290000370000200341e0006a24000f0b200341286a41146a4102360200200341346a4103360200200341106a41146a41033602002003200341086a36024020032003410c6a360244200341c8006a41146a410036020020034203370214200341bc80c0003602102003410336022c200341b48cc0003602582003420137024c2003418881c0003602482003200341286a3602202003200341c8006a3602382003200341c4006a3602302003200341c0006a360228200341106a1a41dc81c0001a00000bf40101037f02400240200041046a2802002203200041086a28020022046b2002490d00200028020021050c010b02400240200420026a22052004490d00200341017422042005200420054b1b22044108200441084b1b22044100480d00024002402000280200410020031b2205450d0020032004460d01024020030d0020044101102c21050c020b200520032004102921050c010b20044101102c21050b2005450d0120002005360200200041046a2004360200200041086a28020021040c020b1027000b2004410141002802f48c402200410420001b110200000b200520046a2001200210221a200041086a200420026a3602000b860201017f230041e0006b22022400200241046a41003b01002002410e6a200041086a290000370100200241166a200041106a2900003701002002411e6a200041186a2f00003b01002002410036020020022000290000370106200241206a41046a41003b0100200241206a410e6a200141086a290000370100200241206a41166a200141106a290000370100200241206a411e6a200141186a2f00003b01002002410036022020022001290000370126200241c0006a41106a4200370300200241c0006a41086a420037030020024200370340200242808080c0cebaa90837035841b48cc0004100410441f681c0002002200241206a200241c0006a1002200241e0006a24000bcb0101027f230041106b22032400024020024101100d2204450d002004200020022001200120024b1b10221a2000450d00200320003602042001450d000240200141036a410276417f6a220241ff014b0d00200341f88cc0003602082003200241027441fc8cc0006a220228020036020c200341046a2003410c6a200341086a41cc8cc00010102002200328020c3602000c010b200341002802f88c4036020c200341046a2003410c6a41b48cc00041b48cc00010104100200328020c3602f88c400b200341106a240020040bb40102017f017e230041c0006b22022400200220002001100e200241386a22004200370300200241306a4200370300200241286a4200370300200242003703202002200241206a100020002903002103200241c0006a24002003423886200342288642808080808080c0ff0083842003421886428080808080e03f8320034208864280808080f01f838484200342088842808080f80f832003421888428080fc07838420034228884280fe038320034238888484840bb20102017f017e230041c0006b2201240020012000100f200141386a22004200370300200141306a4200370300200141286a4200370300200142003703202001200141206a100020002903002102200141c0006a24002002423886200242288642808080808080c0ff0083842002421886428080808080e03f8320024208864280808080f01f838484200242088842808080f80f832002421888428080fc07838420024228884280fe038320024238888484840bad0101017f230041106b2202240002402000450d00200220003602042001450d000240200141036a410276417f6a220041ff014b0d00200241f88cc0003602082002200041027441fc8cc0006a220028020036020c200241046a2002410c6a200241086a41cc8cc00010102000200228020c3602000c010b200241002802f88c4036020c200241046a2002410c6a41b48cc00041b48cc00010104100200228020c3602f88c400b200241106a24000b7f01017f230041c0006b220524002005200136020c2005200036020820052003360214200520023602102005412c6a41023602002005413c6a41053602002005420237021c2005419088c000360218200541063602342005200541306a3602282005200541106a3602382005200541086a360230200541186a1a20041a00000b7301017f02400240200241027422022003410374418080016a2203200220034b1b418780046a220441107640002203417f470d00410121020c010b20034110742203420037030041002102200341003602082003200320044180807c716a4102723602000b20002003360204200020023602000b6d01017f230041306b2203240020032001360204200320003602002003411c6a41023602002003412c6a41013602002003420237020c200341fc86c000360208200341013602242003200341206a3602182003200341046a36022820032003360220200341086a1a20021a00000b6d01017f230041306b2203240020032001360204200320003602002003411c6a41023602002003412c6a41013602002003420237020c200341c486c000360208200341013602242003200341206a3602182003200341046a36022820032003360220200341086a1a20021a00000b6001017f024002402002417f4c0d00024020020d00200041003602082000420137020020002001410010140f0b20024101102c2203450d0120004100360208200020023602042000200336020020002001200210140f0b102f000b20021026000b5c01037f0240024010082201417f4c0d000240024020010d0041012102410021030c010b2001210320014101102c2202450d020b20002001360208200020023602002000200336020420024100200110090f0b102f000b20011026000b4e01017f230041c0006b2201240020012000100f200141306a4200370300200141286a420037030020014200370320200142808080c0cebaa9083703382001200141206a1001200141c0006a24000b4401017f230041206b22012400200141106a4200370300200141086a420037030020014200370300200142808080808080808001370318200020011001200141206a24000b3601017f02402002450d00200021030340200320012d00003a0000200341016a2103200141016a21012002417f6a22020d000b0b20000b3301017f02402001280208220520034f0d00200320052004101d000b2000200320026b3602042000200128020020026a3602000b2b0020004200370000200041186a41003b0000200041106a4200370000200041086a4200370000200010050b2c01017f02402002450d00200021030340200320013a0000200341016a21032002417f6a22020d000b0b20000b1a01017f2000410141002802f48c402201410420011b110200000b130041e483c0001a41111a41f883c0001a00000b0d0020002802001a037f0c000b0b0a0020002001200210160b0900200020011006000b0900410041001007000b080020002001102e0b08002000200110190b080020002001100d0b05001027000b0d0042a98089cda5ebd0e9ae7f0b05004180040b040041010b040020010b040041000b0300000b02000b02000b0bee0c0100418080c0000be40c617373657274696f6e206661696c65643a2060286c656674203d3d20726967687429600a20206c6566743a2060602c0a2072696768743a2060603a20000010002d0000002d0010000c000000390010000300000064657374696e6174696f6e20616e6420736f7572636520736c69636573206861766520646966666572656e74206c656e6774687354001000340000002f72757374632f343763333135386333643739376637356630663762326232613937373137393636383931396461622f7372632f6c6962636f72652f6d6163726f732f6d6f642e7273000000900010004900000010000000090000007372632f6c69622e7273831ac82b07fb396dafef0077cea6e002235d88e63f35cbd5df2c065107f1e74a16304dfea7f3fbabcf59225f0629cb307fecb8d5652b069080aa9be2c765d7d20000ec0010000a000000b60000002c000000ec0010000a000000150100002c000000ec0010000a000000180100002900000002414141414141436f696e00ec0010000a000000fa0000002a000000ec0010000a000000fd0000002c000000ec0010000a000000e50000002a000000ec0010000a000000e80000002e000000ec0010000a000000eb00000029000000ec0010000a000000d70000002e000000ec0010000a000000bf000000200000006361706163697479206f766572666c6f77000000080210001700000044020000050000007372632f6c6962616c6c6f632f7261775f7665632e72735061644572726f72004802100020000000680210001200000008000000000000000100000009000000696e646578206f7574206f6620626f756e64733a20746865206c656e20697320206275742074686520696e646578206973203030303130323033303430353036303730383039313031313132313331343135313631373138313932303231323232333234323532363237323832393330333133323333333433353336333733383339343034313432343334343435343634373438343935303531353235333534353535363537353835393630363136323633363436353636363736383639373037313732373337343735373637373738373938303831383238333834383538363837383838393930393139323933393439353936393739383939000054031000060000005a03100022000000696e64657820206f7574206f662072616e676520666f7220736c696365206f66206c656e677468208c03100016000000a20310000d000000736c69636520696e64657820737461727473206174202062757420656e64732061742000d0031000160000005d04000024000000d00310001600000053040000110000007372632f6c6962636f72652f666d742f6d6f642e72730000fa03100016000000540000001400000030787372632f6c6962636f72652f666d742f6e756d2e7273340610000000000020041000020000003a20000000000000010000000000000082800000000000008a8000000000008000800080000000808b800000000000000100008000000000818000800000008009800000000000808a00000000000000880000000000000009800080000000000a000080000000008b800080000000008b0000000000008089800000000000800380000000000080028000000000008080000000000000800a800000000000000a0000800000008081800080000000808080000000000080010000800000000008800080000000807765206e657665722075736520696e7075745f6c617a79000800000000000000010000000a0000002f726f6f742f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f736861332d302e382e322f7372632f6c69622e7273007c05100053000000280000000d0000007c0510005300000036000000090000002f726f6f742f2e636172676f2f72656769737472792f7372632f6769746875622e636f6d2d316563633632393964623965633832332f626c6f636b2d6275666665722d302e372e332f7372632f6c69622e727300100510004b0000004a0000000100000063616c6c656420604f7074696f6e3a3a756e77726170282960206f6e206120604e6f6e65602076616c7565001c06100017000000830100000f0000007372632f6c69627374642f70616e69636b696e672e7273000800000000000000010000000b0000000c0000000d0000000800000004000000040000000e0000000f00000010000000008d1a046e616d6501829a8080003700355f5a4e39737761736d5f617069366e6174697665313173746f726167654c6f6164313768626361333162336535336130353665384501365f5a4e39737761736d5f617069366e6174697665313273746f7261676553746f7265313768636238303263383263346662396462384502305f5a4e39737761736d5f617069366e617469766537656d69744c6f67313768636237366434316337313532346562394503395f5a4e39737761736d5f617069366e6174697665313567657443616c6c4461746153697a65313768303566373932663832613135626666664504365f5a4e39737761736d5f617069366e6174697665313263616c6c44617461436f7079313768626164356234393137326538326339644505325f5a4e39737761736d5f617069366e61746976653967657443616c6c65723137683638663433643361353232383231393345062f5f5a4e39737761736d5f617069366e61746976653666696e6973683137683632396632373335623934393262333045072f5f5a4e39737761736d5f617069366e617469766536726576657274313768633834356265366663306230653035384508355f5a4e39737761736d5f617069366e61746976653131676574436f646553697a65313768373538353866346234303666363533314509315f5a4e39737761736d5f617069366e617469766538636f6465436f707931376864633363393463323361636564633536450a046d61696e0b245f5a4e366b656363616b35663136303031376833383866336362396130666331313864450c325f5a4e397765655f616c6c6f633135616c6c6f635f66697273745f66697431376862366337333063626363626465323839450d675f5a4e37325f244c54247765655f616c6c6f632e2e576565416c6c6f63247532302461732475323024636f72652e2e616c6c6f632e2e676c6f62616c2e2e476c6f62616c416c6c6f632447542435616c6c6f6331376863343132626562306363663431383166450e3d5f5a4e3130706c617967726f756e64323463616c63756c6174655f616c6c6f77616e63655f6861736831376834343662633366386437633734393761450f3b5f5a4e3130706c617967726f756e64323263616c63756c6174655f62616c616e63655f68617368313768623438313638613033393838633363334510565f5a4e397765655f616c6c6f6338576565416c6c6f6331326465616c6c6f635f696d706c32385f24753762242475376224636c6f73757265247537642424753764243137686366333733393464336139353930393845112d5f5a4e3473686133394b656363616b323536366162736f726231376833373166386431663564663162396238451289015f5a4e38385f244c54247765655f616c6c6f632e2e73697a655f636c61737365732e2e53697a65436c617373416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c6963792447542432326e65775f63656c6c5f666f725f667265655f6c697374313768643730383166303262333337643631634513525f5a4e34636f726535736c69636532395f244c5424696d706c24753230242475356224542475356424244754243135636f70795f66726f6d5f736c696365313768336263663632336331303864333766394514425f5a4e35616c6c6f63337665633132566563244c542454244754243137657874656e645f66726f6d5f736c696365313768366562326135396437313731326166324515325f5a4e3130706c617967726f756e643133656d69745f7472616e736665723137683134393265383261616663363233623545160c5f5f72675f7265616c6c6f6317325f5a4e3130706c617967726f756e6431336765745f616c6c6f77616e6365313768306564333131656465653437363238634518305f5a4e3130706c617967726f756e6431316765745f62616c616e63653137683164373038313362633638643535323245190c5f5f72675f6465616c6c6f631a375f5a4e34636f7265366f7074696f6e31386578706563745f6e6f6e655f6661696c656431376836383432633035363039613131616134451b775f5a4e37305f244c54247765655f616c6c6f632e2e4c61726765416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c6963792447542432326e65775f63656c6c5f666f725f667265655f6c69737431376861386439306430346234373763636631451c3a5f5a4e34636f726535736c6963653232736c6963655f696e6465785f6f726465725f6661696c31376831646533363762613337376463653864451d385f5a4e34636f726535736c6963653230736c6963655f696e6465785f6c656e5f6661696c31376831393837356266643638383464663863451e495f5a4e35616c6c6f6335736c69636532395f244c5424696d706c247532302424753562245424753564242447542436746f5f76656331376862313735303132356663396236643934451f2f5f5a4e39737761736d5f6170693132636f64655f61637175697265313768306139616536373833353736383237384520305f5a4e3130706c617967726f756e6431317365745f62616c616e63653137683762663132613961646464306530396145212d5f5a4e3130706c617967726f756e643973746f72655f753634313768343765623965646232333631616261654522066d656d637079236c5f5a4e37375f244c5424616c6c6f632e2e7665632e2e566563244c54245424475424247532302461732475323024636f72652e2e6f70732e2e696e6465782e2e496e646578244c542449244754242447542435696e646578313768323633393232653034616435653437644524285f5a4e39737761736d5f6170693663616c6c6572313768626663333030383964346135346235384525066d656d73657426655f5a4e35616c6c6f63377261775f7665633139526177566563244c54245424432441244754243131616c6c6f636174655f696e32385f24753762242475376224636c6f7375726524753764242475376424313768303435323836623166393339336563334527385f5a4e35616c6c6f63377261775f766563313763617061636974795f6f766572666c6f773137683932663733663364376366326334386245283a5f5a4e34636f7265336f70733866756e6374696f6e36466e4f6e63653963616c6c5f6f6e63653137683630303733356432666138643730666445290e5f5f727573745f7265616c6c6f632a2e5f5a4e39737761736d5f617069313166696e6973685f6461746131376834376666633837623536613265353631452b285f5a4e39737761736d5f6170693672657665727431376831333361623961393366323865343930452c0c5f5f727573745f616c6c6f632d0e5f5f727573745f6465616c6c6f632e0a5f5f72675f616c6c6f632f655f5a4e35616c6c6f63377261775f7665633139526177566563244c54245424432441244754243131616c6c6f636174655f696e32385f24753762242475376224636c6f7375726524753764242475376424313768623962663631333239396335643961304530455f5a4e33365f244c542454247532302461732475323024636f72652e2e616e792e2e416e792447542437747970655f69643137683030656262313435663432323530316545316e5f5a4e37305f244c54247765655f616c6c6f632e2e4c61726765416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c6963792447542431336d696e5f63656c6c5f73697a6531376835626131333535356464363734313639453281015f5a4e37305f244c54247765655f616c6c6f632e2e4c61726765416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c69637924475424333273686f756c645f6d657267655f61646a6163656e745f667265655f63656c6c7331376832343132393064643332636337353466453380015f5a4e38385f244c54247765655f616c6c6f632e2e73697a655f636c61737365732e2e53697a65436c617373416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c6963792447542431336d696e5f63656c6c5f73697a6531376864393534643666653439363231323436453493015f5a4e38385f244c54247765655f616c6c6f632e2e73697a655f636c61737365732e2e53697a65436c617373416c6c6f63506f6c6963792475323024617324753230247765655f616c6c6f632e2e416c6c6f63506f6c69637924475424333273686f756c645f6d657267655f61646a6163656e745f667265655f63656c6c733137683937613834353435656232623330626545363b5f5a4e3373746435616c6c6f63323464656661756c745f616c6c6f635f6572726f725f686f6f6b3137683935643237666166346361386434663145372f5f5a4e34636f726533707472313364726f705f696e5f706c6163653137683034303333326338353662313463623745";
const hdKeys = crypto.keysGen.fromPrivateKey(privKey);
const wallet = hdKeys.toWallet();
const resp = await client.consumedFee(wallet.Base58Address, null, payload);
const nonce = await client.getNonce(wallet.Base58Address);
const commission = resp.consumedFee.plus(COMMISSION);
let tx = crypto.tx.generateTx()
.addCommission(gasPrice, COMMISSION)
.addSender(wallet.Base58Address, hdKeys, commission, nonce.unconfirmedNonce)
.addContractCreation(wallet.Base58Address, payload, toBigInt(0), commission)
.sign();
try {
console.log(tx.toJSON());
const data = await client.send(tx);
console.log(data);
} catch (e) {
console.error(e);
}
exec contract
const client = new Client(baseUrl);
const crypto = await Crypto.init();
const contract = "SXkW7KXHaFRjA5ry8UvuKvexpXV82xoHMxz";
const payload = "5d359fbd0e30aa5ec7b2737507febba04337c6f09c645811b25e5ff9c4bc0000000000001388";
const hdKeys = crypto.keysGen.fromPrivateKey(privKey);
const wallet = hdKeys.toWallet();
const resp = await client.consumedFee(wallet.Base58Address, contract, payload);
const nonce = await client.getNonce(wallet.Base58Address);
const commission = resp.consumedFee.plus(COMMISSION);
let tx = crypto.tx.generateTx()
.addCommission(gasPrice, COMMISSION)
.addSender(wallet.Base58Address, hdKeys, commission, nonce.unconfirmedNonce)
.addContractExecution(wallet.Base58Address, contract, payload, toBigInt(0), commission)
.sign();
try {
console.log(tx.toJSON());
const data = await client.send(tx);
console.log(data);
} catch (e) {
console.error(e);
}
make erc20 transfer
const baseUrl = "https://testnet.sonocoin.io/api/rest/v1";
const contract = 'SXY3xT8FnCfNTTZF3si777QyXAdwALP3QSu';
const address = 'SCg1YUnoZA6mwQr4vuXQhi1158JHGguotjY';
const amount = toBigInt(100);
const client = new Client(baseUrl);
let sonoCrypto = await Crypto.init();
const hdKeys = sonoCrypto.keysGen.fromPrivateKey(privKey);
const wallet = hdKeys.toWallet();
const consumedFee = await client.erc20.getTransferFee(wallet.Base58Address, contract, address, amount);
const nonce = await client.getNonce(wallet.Base58Address);
const commission = consumedFee.plus(COMMISSION);
let tx = sonoCrypto.tx.generateErc20Transfer()
.addSender(wallet.Base58Address, hdKeys, commission, nonce.unconfirmedNonce)
.addTransfer(contract, address, amount, commission)
.sign();
try {
console.log(tx.toJSON());
const data = await client.send(tx);
console.log(data);
} catch (e) {
console.error(e);
}