Transaction Relayer, allows you to seamlessly enable gas-less transactions for your users.
It first creates a custodial wallet which gets mapped to your Shyft API key. On creation, it returns the wallet address associated with you SHYFT API key. You have to use this wallet address as,fee_payer while constructing your transactions. Then, you can send the transactions that need to be signed on the relayer’s sign endpoint. Relayer will retrieve the credentials associated with your API key, sign the transaction and send it to the blockchain.
Create Relayer
Create a new transaction relayer.
POST /sol/v1/txn_relayer/create
Headers:
x-api-key: Your API key
var myHeaders = new Headers();
myHeaders.append("x-api-key", "<YOUR-API-KEY>");
var requestOptions = {
method: 'POST',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.shyft.to/sol/v1/txn_relayer/create", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
{
"success": true,
"message": "A wallet bound with your API Key",
"result": {
"wallet": "GzMBRTvt5iyRsVizd5qKqJrKRJ4F2cyrdisRhUKEevTi"
}
}
Sign Transaction
Sign and send a transaction using the relayer. Takes encoded_transaction and network as input request parameters.
encoded_transactions: An array of serialized transactions (base64 string).
commitment (optional): If the response is needed after a certain commitment level reaches all the transactions, pass the desired commitment level (allowed processed, confirmed, finalized).
If the commitment level is specified, the response time may increase because the system will wait for all transactions to reach the requested commitment level before responding.
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "YOUR_API_KEY");
var raw = JSON.stringify({
"network": "devnet",
"encoded_transactions": [
"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDX26hu/mTZjDVkpJ2jU6FftnXFJGy5KcBJoXAaXHIMdpALAeVfwkorAqlrAeN8dOn8Jeu6H4u3ofHzGz4FntQPwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0ihHHsVZsH9hW04rx4QZ+LTAoGxUuyawjkhtv3ao2aEBAgIAAQwCAAAAQEIPAAAAAAA=",
"AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDX26hu/mTZjDVkpJ2jU6FftnXFJGy5KcBJoXAaXHIMdosLagmF5c4a6vJhMr74YTUznxniMs9+z4QYlMJ1x2b+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHubOmafFh4bvNPqY+AdQdzrv43WzBksnfAcdQd03Y40BAgIAAQwCAAAAgIQeAAAAA"
],
"commitment": "finalized"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://api.shyft.to/sol/v1/txn_relayer/sign_many", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));