-
Notifications
You must be signed in to change notification settings - Fork 153
Trouble burning tokens #235
-
Hi guys,
I just keep getting errors when trying to burn tokens. My code is below, I have several questions.
In your example, you use Compile message. when doing so, I get the error:TX1.Length 202
Simulation:
{"jsonrpc":"2.0","error":{"code":-32602,"message":"io error: failed to fill whole buffer"},"id":6}
What is the difference between compile message and build?
Im also having trouble figuring out the proper account data, as when I use Build, I get:
{"jsonrpc":"2.0","result":{"context":{"slot":87464108},"value":{"accounts":null,"err":{"InstructionError":[0,"InvalidAccountData"]},"logs":["Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]","Program log: Instruction: Burn","Program log: Error: InvalidAccountData","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1446 of 200000 compute units","Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction"]}},"id":4}
The token im trying to burn is: 5tXwi4BnyWvR1qB8DMMN1n3AA5JzwQvtfLZAyykjpJcz found on the devnet.
Many thanks,
Paulo
`public async void Burn (string tokenAddress, ulong amount)
{
TransactionInstruction tiBurn = TokenProgram.Burn
(
new PublicKey(tokenAddress),
wallet.Account.PublicKey,
amount,
wallet.Account.PublicKey
);
RequestResult<ResponseValue<BlockHash>> blockHash = await RpcClient.GetRecentBlockHashAsync();
byte[] TX1 = new TransactionBuilder()
.SetRecentBlockHash(blockHash.Result.Value.Blockhash)
.SetFeePayer(wallet.Account.PublicKey)
.AddInstruction(tiBurn) //burn
.AddInstruction(MemoProgram.NewMemo(wallet.Account, "Hello from Sol.Net"))
.CompileMessage();
//.Build(new List<Account> { wallet.Account });
Console.WriteLine($"TX1.Length { TX1.Length }");
var txSim = await RpcClient.SimulateTransactionAsync(TX1);
Console.WriteLine($"Simulation: \n { txSim.RawRpcResponse } ");
}`
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
make sure you are passing correct parameters. for instance i can see that first parameter is wrong, you are passing mintAddress, which is second parameter, first one is associated token adddress of the source public key where token is held, etc.
Beta Was this translation helpful? Give feedback.
All reactions
-
how about this,
public byte[] CreateBurn(Account from, LatestBlockHash blockHash, ulong amount)
{
var tx = new TransactionBuilder().
SetRecentBlockHash(blockHash.Blockhash).
SetFeePayer(from).
AddInstruction(TokenProgram.Burn(from, Program.WorkenMintPublicKey, amount, from)).
AddInstruction(MemoProgram.NewMemo(from, Guid.NewGuid().ToString())).
Build(from);
return tx;
}
used in
[HttpPost("Burn")]
public async Task<IActionResult> CreateBurn([FromBody] CreateBurnRequest burnRequest)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var client = rpcService.GetClientMainNet();
var blockHash = await rpcService.GetRecentBlockHash(client);
Account fromAccount = new(burnRequest.FromAccountPrivateKey, burnRequest.FromAccountPublicKey);
var transactionData = transactionsService.CreateBurn(fromAccount, blockHash, burnRequest.Amount);
var transactionHash = await rpcService.SendTransaction(client, transactionData);
if (transactionHash.Exception != null) return BadRequest(transactionHash.Exception);
return Content(transactionHash.Result);
}
but still gets error
{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32002,\"message\":\"Transaction simulation failed: Error processing Instruction 0: invalid account data for instruction\",\"data\":{\"accounts\":null,\"err\":{\"InstructionError\":[0,\"InvalidAccountData\"]},\"logs\":[\"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]\",\"Program log: Instruction: Burn\",\"Program log: Error: InvalidAccountData\",\"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1163 of 400000 compute units\",\"Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA failed: invalid account data for instruction\"],\"returnData\":null,\"unitsConsumed\":0}},\"id\":1}\n
Beta Was this translation helpful? Give feedback.