Arkana Docs
Search
K

Meta Transaction

Build a seamless web3 UX by covering users' gas fees

Background

In-protocol meta transactions allowing for third-party account to initiate and pay transaction fees on behalf of the account. https://github.com/near/NEPs/pull/366
Another hurdle for new users is that they need to pay gas fees to interact with apps. To simplify the experience the platform can cover all gas fees with Meta Transaction. Currently, all on-chain interactions in Arkana are covered. All transactions are signed and will be sent by the users' account and the platform just merely paid for gas fees, don't worry!

How it works

  1. 1.
    Create an on-chain function calls and wrap them with signedDelegate from @near-js/transactions
  2. 2.
    Send the signed transaction to a meta tx's relayer
This is best explained by the code below.

Code Sample

const { Account } = require('@near-js/accounts')
const { JsonRpcProvider } = require('@near-js/providers')
const { PublicKey } = require('@near-js/crypto')
const { InMemorySigner } = require('@near-js/signers')
const {
actionCreators,
SCHEMA,
SignedDelegate,
encodeSignedDelegate,
} = require('@near-js/transactions')
const { KeyPair, connect } = require('near-api-js')
const { InMemoryKeyStore } = require('near-api-js/lib/key_stores')
const main = async () => {
const accountId = 'youraccount.near'
const secretKey = 'redacted'
const { networkId, nodeUrl } = getConfig('testnet')
const provider = new JsonRpcProvider({ url: nodeUrl })
const signer = await InMemorySigner.fromKeyPair(networkId, accountId, secretKey)
const signerAccount = new Account({ networkId, provider, signer }, accountId)
const actionDelegate = await signerAccount?.signedDelegate({
actions: [
actionCreators.functionCall(
'ft_transfer',
{
receiver_id: 'u.arkana.near',
amount: '1000000',
},
'10000000000000',
0
),
],
blockHeightTtl: 60,
receiverId: 'usdt.tether-token.near',
})
const delegate = JSON.stringify(Array.from(encodeSignedDelegate(actionDelegate)))
const res = await axios.post(
`{arkanaBackendHost}/v2/transaction`,
{
delegate,
account_id: accountId,
},
{
headers: {
Authorization: {jwtAuth},
},
}
)
}
main()