Sponsorship Tx

sponsorship transaction

Transaction sponsorship is a mechanism that allows users to sponsor any transaction with a third party via CPU and NET bandwidth. This means that CPU and NET costs will be fully covered by the sponsoring account.

Description

The mechanism is implemented at the core level of the DAObet blockchain. To create such a transaction, two parties will have to participate: the original author of the transaction (sender) and the sponsor (sponsor). A transaction is sent to the blockchain only after complete formation, i.e. the signatures of both parties.

Transaction Creation

The creation of a transaction takes place in two stages, examples with excerpts of JS code are given using the eosjs:

A sender transaction is formed, for this a transaction signature is created with a special extension (action_extension):

// ABI for transaction extension, required for serialize transaction
const ext_abi = {
"version": "eosio::abi/1.0",
"structs": [
{
"name": "sponsor_ext",
"base": "",
"fields": [
{
"name": "sponsor",
"type": "name"
},
]
}
],
};
// Serializing extension
let buffer = new Serialize.SerialBuffer({ textEncoder: new TextEncoder(), textDecoder: new TextDecoder() });
const sponsorType = Serialize.getTypesFromAbi(api.abiTypes, ext_abi).get('sponsor_ext');
sponsorType.serialize(buffer, {"sponsor": "<SPONSOR_ACCOUNT_NAME>"});
api.transact({
actions: [{
//TODO some actions
}],
transaction_extensions: [{
type: 0,
data: Serialize.arrayToHex(buffer.asUint8Array())
}]
}).then(async (trx) => {
// TODO send trx TO sponsor
});

Signature of the transaction and sending to the blockchain by the sponsor:

// get trx from sender
// Signing trx from sender via sponsor public key
trx = await signatureProvider.sign({
chainId: api.chainId,
requiredKeys: pubkeys,
serializedTransaction: trx.serializedTransaction
});
// Sending fulfilled transaction to blockchain
await api.pushSignedTransaction(trx);