|
| 1 | +# Mx.NET.SDK.SmartSend |
| 2 | +⚡ MultiversX SmartSend TypeScript SDK: Library for interacting with Smart Send contracts on MultiversX blockchain |
| 3 | + |
| 4 | +## How to install? |
| 5 | +The content is delivered via npm package: |
| 6 | +##### [@remarkabletools/mx-smartsend](https://www.npmjs.com/package/@remarkabletools/mx-smartsend) |
| 7 | + |
| 8 | +## Main Features |
| 9 | +- Create EGLD/Token/MetaESDT/NFT/SFT transactions for Smart Send contracts |
| 10 | + |
| 11 | +## Quick start guide |
| 12 | +### Basic example |
| 13 | +```javascript |
| 14 | +const provider = new ProxyNetworkProvider('https://devnet-gateway.multiversx.com') |
| 15 | +const networkConfig = await provider.getNetworkConfig() |
| 16 | + |
| 17 | +const myaddress = Address.fromBech32('MY_ADDRESS') |
| 18 | +const accountOnNetwork = await provider.getAccount(myaddress) |
| 19 | +const account = new Account(myaddress) |
| 20 | +account.update(accountOnNetwork) |
| 21 | + |
| 22 | +const smartSend = new SmartSend(account, networkConfig, 'MY_CONTRACT_BECH32_ADDRESS') |
| 23 | + |
| 24 | +const inputTransactions = [] |
| 25 | +for (let i = 1; i < 10; i++) { |
| 26 | + inputTransactions.push(new TokenAmount('RECEIVER_ADDRESS', TokenTransfer.egldFromAmount('0.0' + i))) // TokenTransfer can also be fungibleFromAmount / metaEsdtFromAmount / nonFungible / semiFungible |
| 27 | +} |
| 28 | + |
| 29 | +try { |
| 30 | + const txs = smartSend.createEGLDTransactions(inputTransactions) // or createTokenTransactions / createMetaESDTTransactions / createNFTTransactions / createSFTTransactions |
| 31 | + // sign and send egldTxs |
| 32 | +} catch (error) { |
| 33 | + console.log(error) |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +### Advanced example |
| 38 | +*The following example is using a wallet __signer__ that should not be used in production, only in private!* |
| 39 | +```javascript |
| 40 | +const provider = new ProxyNetworkProvider('https://devnet-gateway.multiversx.com') |
| 41 | +const networkConfig = await provider.getNetworkConfig() |
| 42 | + |
| 43 | +const myaddress = Address.fromBech32('MY_ADDRESS') |
| 44 | +const accountOnNetwork = await provider.getAccount(myaddress) |
| 45 | +const account = new Account(myaddress) |
| 46 | +account.update(accountOnNetwork) |
| 47 | + |
| 48 | +const pemText = await promises.readFile('/path/wallet.pem', { encoding: 'utf8' }) |
| 49 | +const signer = UserSigner.fromPem(pemText) |
| 50 | + |
| 51 | +const smartSend = new SmartSend(account, networkConfig, 'MY_CONTRACT_BECH32_ADDRESS') |
| 52 | + |
| 53 | +const inputTransactions = [] |
| 54 | +for (let i = 1; i < 10; i++) { |
| 55 | + inputTransactions.push(new TokenAmount('RECEIVER_ADDRESS', TokenTransfer.fungibleFromAmount('TOKEN-123456', i, 18))) // TokenTransfer can also be fungibleFromAmount / metaEsdtFromAmount / nonFungible / semiFungible |
| 56 | +} |
| 57 | + |
| 58 | +try { |
| 59 | + const tokenTxs = smartSend.createTokenTransactions(inputTransactions) |
| 60 | + for (const tx of tokenTxs) { |
| 61 | + const serializedTransaction = tx.serializeForSigning() |
| 62 | + const transactionSignature = await signer.sign(serializedTransaction) |
| 63 | + tx.applySignature(transactionSignature) |
| 64 | + } |
| 65 | + |
| 66 | + const response = await provider.sendTransactions(tokenTxs) |
| 67 | + console.log(response) |
| 68 | +} catch (error) { |
| 69 | + console.log(error) |
| 70 | +} |
| 71 | +``` |
0 commit comments