secretshardul
secretshardul

Reputation: 1873

Near protocol equivalent of buring NEAR tokens by sending to address(0)

I want to delete the current contract and burn its NEAR balance when a condition is triggered.

Here's the Solidity version:

selfdestruct(address(0));

I found Promise::delete_account in the Rust SDK but it has a beneficiary_address field. Ideally the funds should be gone forever and not transferred to an owned address.

Promise::new(env::current_account_id()).delete_account(beneficiary_address);

address(0) is address 0x0, a black hole address used to burn Ether.

Upvotes: 0

Views: 699

Answers (2)

Dario Sanchez
Dario Sanchez

Reputation: 1

I think that is like this:

#[payable]
pub fn burn() {  
 Promise::new("system".to_string()).transfer(env::attached_deposit());
}

First importing:

use near_sdk::{Promise};

Upvotes: 0

berryguy
berryguy

Reputation: 1154

Currently there is no API to burn NEAR tokens directly. One workaround is to set the beneficiary account id to system. system is an account that can never be created and is used internally for refunds. When the beneficiary account does not exist, the tokens transferred through account deletion are automatically burnt.

Upvotes: 2

Related Questions