How to change asset manager from contract side

Hi I want to change asset manager through contract side. I did some R&D and I think Txn.config_asset_manager() through this I can change but i am unable to use it in my smart contract can somebody let me know how can I write subroutine that can change manager of the asset.

Thank You

To change the asset manager, you need to issue an asset configuration inner transaction: Smart contract details - Algorand Developer Portal

This is assuming that the application account of your smart contract is already the asset manager of the asset. Otherwise you cannot do it.

So while creating the app I need to make app address the manager and then while transfer the asset i need to make the buyer the manager, write ?

It depends on the use case. If you need the buyer to become the manager after selling, yes.
Why do you need that though?

Usually ownership is done via “asset transfer”.
Manager is really used just to be able to change the freezing address / clawback address / reserve address.

Actually when I tried to resale that asset it gives me error that this transaction should be issued by manager and at that time manager was the one who minted that asset that is why I need to change the manager so that I can overcome this error.

What steps are you taking to try to “resale” the asset?
Can you show the code you are using to “resale” the asset?
Has the asset any restrictions (e.g., frozen)?
Can you show it on TestNet on a fake asset?
(give the asset ID on TestNet)

Well steps are same as of the 1st time. First I mint the NFT and then creating the app after this I put the NFT on sale, and I am not deleting the application id so when I resale the NFT I will not create the app again but that is the difference in resale, Here is the TestNet asset id you can check:

152083452

And here is the asset creation code:

const params = await algodClient.getTransactionParams().do();
	const decimals = 0;
	const defaultFrozen = false;

	const unitName = assetName.substring(0, 6);

	const txn = algosdk.makeAssetCreateTxnWithSuggestedParamsFromObject({
		assetName: assetName,
		assetURL: metaData.metaDataUrl,
		decimals: decimals,
		defaultFrozen: defaultFrozen,
		from: connectedAddress.toString(),
		suggestedParams: params,
		total: 1,
		unitName: unitName,
		manager: connectedAddress.toString(),
		freeze: connectedAddress.toString(),
		clawback: connectedAddress.toString(),
	});

Here is how I fund the app:

const fundAppTxn =
			await algosdk.makePaymentTxnWithSuggestedParamsFromObject({
				suggestedParams: {
					...params,
				},
				from: accountaddress.toString(),
				to: app_address,
				amount: fundingAmount,
			});

And here is how I can configure the asset:

const tx = await algosdk.makeAssetConfigTxnWithSuggestedParamsFromObject({
			from: connectedAddress.toString(),
			assetIndex: nftID,
			clawback: appAddr,
			freeze: appAddr,
			suggestedParams: params,
			strictEmptyAddressChecking: false,
			manager: appAddr,
		});

What is the application used for in your context?

It looks your asset is not frozen.

So anyone owning it can move it to another address using makeAssetTransferTxnWithSuggestedParamsFromObject.

1 Like

I am transferring asset through contract using inner transaction. Is it good practice to send asset using algosdk ?

Unless you need special properties such as royalty payment, the simplest solution is to transfer directly using the SDK, without a smart contract.

If you want royalty payments or similar features, see ARC-18: Royalty Enforcement Specification, GitHub - algorand-devrel/royalty, and ARC-20: Smart ASA

Also note that a transfer via smart contract would require to use the clawback mechanism as the smart contract is not the owner of the asset in your case. The owner is still the creator.

Yes I am sending royalty payment as well that is why doing all the transactions through smart contract, thank you for your help really appreciated.

Note that your current set up does not enforce royalty payment since the ASA is not frozen by default.
This means that anyone using directly the SDK/goal command/wallet can bypass the royalties at resale, just by issuing an ASA transfer transaction.

To enforce royalties, you need the ASA to be frozen by default (even then, there may be way to bypass it, but it’s harder).

Thank You @fabrice for letting me know about all this. Actually I am just at initial stage of learning Algorand so that is why not have enough knowledge about this, I will surely implement these with the passage of time.