The documentations show how to initialize a new mint with a transfer fee, using createInitializeTransferFeeConfigInstruction()
.
My question is how to modify the transfer fee configuration later? Preferably in JS/TS.
The documentations show how to initialize a new mint with a transfer fee, using createInitializeTransferFeeConfigInstruction()
.
My question is how to modify the transfer fee configuration later? Preferably in JS/TS.
There's a missing instruction creator for the SetTransferFee
instruction in the JS library, which is an oversight.
It's certainly possible, but only through the CLI currently with spl-token set-transfer-fee
, e.g.:
$ spl-token set-transfer-fee <MINT_ID> <FEE_IN_BASIS_POINTS> <MAX_FEE>
Once it is set, there is no way to update the transfer fee for the mint.
Here's how I'm doing it with Rust:
Creating the extension with transfer_fee_basis_points = 0:
fn initialize_transfer_fee(ctx: &mut Context<LaunchToken>) -> Result<()> {
invoke(
&initialize_transfer_fee_config(
&ctx.accounts.token2022_program.key(),
&ctx.accounts.mint.key(),
Some(&ctx.accounts.mint.key()),
Some(&ctx.accounts.mint.key()),
0,
TOTAL_SUPPLY,
)
.unwrap(),
&[ctx.accounts.mint.to_account_info()],
)?;
Ok(())
}
Updating it later on:
fn update_transfer_fee(ctx: &mut Context<UpdateToken>, mint_biz_id: String) -> Result<()> {
invoke_signed(
&set_transfer_fee(
&ctx.accounts.token2022_program.key(),
&ctx.accounts.mint.key(),
&ctx.accounts.mint.key(),
&[&ctx.accounts.mint.key()],
ctx.accounts.pool_data.transfer_fee_basis_points,
TOTAL_SUPPLY,
)
.unwrap(),
&[ctx.accounts.mint.to_account_info()],
signer_seeds
)?;
Ok(())
}
Hope it helps