Mainnet

Prepare transaction

First, let's load Octane node configuration to know how many tokens we should transfer to pay for their transaction and which account will be the fee payer:
const response = (await axios.get('https://octane-devnet.breakroom.show/api', {
headers: {'Accept': 'application/json'}
})).data;
const feePayer = new PublicKey(response.feePayer);
// First token in the list is normally USDC:
const mint = new PublicKey(response.endpoints.transfer.tokens[0].mint);
const simpleTransactionFee = response.endpoints.transfer.tokens[0].fee;
We'll also need some additional information for token transfers:
// `userPublicKey` should be loaded from wallet adapter
const userTokenAccount = await getAssociatedTokenAddress(mint, userPublicKey);
// Let's say we want to send the transfer to this public key
const targetOwner = new PublicKey('EmMC1F6X25qsnXVzNzKUyqFWfLF2GsVJW55fGJRm9feY');
const targetAccount = await getAssociatedTokenAddress(mint, targetOwner);
Now, we're ready to create the transaction with two instructions:
  • First instruction sends token fee to Octane's account
  • Second instruction ("arbitrary" or "payload") executes the token transfer to the friend (but this transaction could be anything else)
We also should set feePayer and recentBlockhash, and then sign the transaction using the end user wallet.
const transaction = new Transaction();
transaction.add(createTransferInstruction(userTokenAccount, tokenAccount.address, userPublicKey, simpleTransactionFee));
transaction.add(createTransferInstruction(userTokenAccount, targetAccount, userPublicKey, 100));
transaction.feePayer = feePayer;
transaction.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;
await signTransaction(transaction);

Submit transaction

Now, we have the transaction with end user's signature. However, the transaction lacks signature of fee payer.
We need to call an Octane HTTP endpoint to get transaction signed and submitted to the network:
const octaneResponse = (await axios.post('https://octane-devnet.breakroom.show/api/transfer', {
transaction: base58.encode(transaction.serialize({requireAllSignatures: false})),
})).data;
console.log(octaneResponse);
It's done!
Last modified 4mo ago