Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Raiblocks add send block to account
//NOTE: Connection = promisified wrapper around RPC calls...methods map directly to RPC 'action' parameter
import Rai from '../server/util/rai'
const Connection = Rai('http://000.000.000.000', 7076) //node IP and port
const SENDER_XRB_WALLET_ADDRESS = 'xrb_...'
const RECEIVING_WALLET = 'xrb_...'
const SENDER_PUBLIC_WALLET_KEY = '....'
async function sendBlock() {
try {
//step 1: Get SENDER'S wallet's balance from acct. info
const { balance } = await Connection.account_info(SENDER_XRB_WALLET_ADDRESS)
//step 2: Get SENDER's wallet's most recent block hash
const { hash } = (await Connection.account_history(
SENDER_XRB_WALLET_ADDRESS
)).history[0]
//step 3: create new SEND block using SENDER's private wallet key
const newBlock: {
hash: string
block: string
} = await Connection.block_create({
type: 'send',
key: process.env.SENDER_PRIVATE_KEY,
account: SENDER_XRB_WALLET_ADDRESS,
destination: RECEIVING_WALLET,
balance: balance,
amount: '1000000000000',
previous: hash
})
// step 5. perform proof of work on the newly created SEND block
const powForBlock: string = await Connection.work_generate(newBlock.hash)
// step 6. publish SEND block to the network??
return Connection.publish({
//pass stringified result of block_create with amount in hex??
block: JSON.stringify(???)
})
} catch (err) {
console.warn(err.message)
}
//step 2: using this hash from step 1, go do work and return checksum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.