Last active
February 12, 2020 16:51
-
-
Save kristjank/68987679a9c6ec29e828dd51069cde70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Transactions , Managers, Utils} from "@arkecosystem/crypto"; | |
import * as request from "request"; | |
/** | |
* Simple example of a transfer transaction using | |
* @arkecosystem/crypto https://github.com/ArkEcosystem/core/tree/develop/packages/crypto | |
* | |
**/ | |
Managers.configManager.setHeight(4006000); | |
const senderWalletAddress = "D8rr7B1d6TL6pf14LgMz4sKp1VBMs6YUYD"; | |
const recipientWalletAddress = "DBoKkzKAT6YdXhyv1mvcKEg97JxiRqMuK2"; | |
const senderPassphrase = "master dizzy era math peanut crew run manage better flame tree prevent"; | |
(async () => { | |
let nonce; | |
await request.get("http://dexplorer.ark.io/api/wallets/" + senderWalletAddress, | |
async (error: any,response: any, body:any)=>{ | |
// This is where we pull out nonce and increment it by one | |
nonce = JSON.parse(body).data.nonce; | |
nonce = Utils.BigNumber.make(nonce).plus(1); | |
// This is where we build our transaction | |
const trx = Transactions.BuilderFactory.multiPayment() | |
.version(2) | |
.nonce(String(nonce)) | |
.addPayment(recipientWalletAddress, "100") | |
.addPayment(recipientWalletAddress, "100") | |
.addPayment(recipientWalletAddress, "100") | |
.sign(senderPassphrase); | |
const transaction = trx.build().toJson(); | |
// This is where we send out transaction to ark node | |
request.post("https://dexplorer.ark.io/api/transactions",{ | |
json: { | |
transactions: [ | |
{ | |
version: transaction.version, | |
network: transaction.network, | |
typeGroup: transaction.typeGroup, | |
type: transaction.type, | |
nonce : transaction.nonce, | |
senderPublicKey:transaction.senderPublicKey, | |
fee: transaction.fee, | |
amount: transaction.amount, | |
expiration: transaction.expiration, | |
recipientId: transaction.recipientId, | |
signature: transaction.signature, | |
id: transaction.id, | |
asset: transaction.asset | |
} | |
] | |
} | |
},(error: any,response: any, body:any)=>{ | |
console.log(body); | |
}) | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment