Packing and Signing
Some API end points require a transaction to be packed and signed using user’s FIO Private Key.
Unpacked transaction
The following is a spec for the unpacked transaction.
account
string
See specific call spec.
required
name
string
See specific call spec.
required
authorization
array[object]
required
data
object
Content of specific call
required
Packing and signing
This is a full example that includes the external RPC code you plan to use outside of the FIO instance:
const { Fio } = require('fiojs');
const { TextEncoder, TextDecoder } = require('text-encoding');
const fetch = require('isomorphic-fetch') // or 'node-fetch'
info = await (await fetch(httpEndpoint + '/v1/chain/get_info')).json();
blockInfo = await (await fetch(httpEndpoint + '/v1/chain/get_block', {body: `{"block_num_or_id": ${info.last_irreversible_block_num}}`, method: 'POST'})).json()
chainId = info.chain_id;
currentDate = new Date();
timePlusTen = currentDate.getTime() + 10000;
timeInISOString = (new Date(timePlusTen)).toISOString();
expiration = timeInISOString.substr(0, timeInISOString.length - 1);
transaction = {
expiration,
ref_block_num: blockInfo.block_num & 0xffff,
ref_block_prefix: blockInfo.ref_block_prefix,
actions: [{
account: 'fio.address',
name: 'regaddress',
authorization: [{
actor: 'aftyershcu22',
permission: 'active',
}],
data: {
fio_address: 'purse:alice',
owner_fio_public_key: 'FIO8PRe4WRZJj5mkem6qVGKyvNFgPsNnjNN6kPhh6EaCpzCVin5Jj'
max_fee: 30000000000,
tpid: 'rewards:wallet',
actor: 'aftyershcu22',
},
}]
};
abiMap = new Map()
tokenRawAbi = await (await fetch(httpEndpoint + '/v1/chain/get_raw_abi', {body: `{"account_name": "fio.address"}`, method: 'POST'})).json()
abiMap.set('fio.system', tokenRawAbi)
tx = await Fio.prepareTransaction({transaction, chainId, privateKeys, abiMap,
textDecoder: new TextDecoder(), textEncoder: new TextEncoder()});
pushResult = await fetch(httpEndpoint + '/v1/chain/register_fio_address', {
body: JSON.stringify(tx),
method: 'POST',
});
json = await pushResult.json()
if (json.processed && json.processed.except) {
throw new RpcError(json);
}
expect(Object.keys(json)).toContain('transaction_id');