Do stateful smart contracts need to opt into ASAs? I know stateful smart contracts have an address like any other account, so can I send any ASA to it? If so, how does the smart contract opt into the asset?
Hi, please refer to this:
Link
1 Like
const algosdk = require('..');
const server = 'https://testnet-algorand.api.purestake.io/ps2';
const port = '';
const token = {
'x-api-key': 'B3SU4KcVKi94Jap2VXkK83xx38bsv95K5UZm2lab', // fill in yours
};
// const bobmnemonic = 'curious duck pet daughter setup pretty surface saddle arm neck side guard alter tree turtle release shoe vivid power solid trim escape snack above page'; // fill in yours
// const bobAccount = algosdk.mnemonicToSecretKey(bobmnemonic);
const client = new algosdk.Algodv2(token, server, port);
(async () => {
const params = await client.getTransactionParams().do();
const program = 'int 1';
const compiledProgram = await client.compile(program).do();
const programBytes = new Uint8Array(
Buffer.from(compiledProgram.result, 'base64')
);
// Initialize arguments array
const args = [];
// Integer parameter
args.push(algosdk.encodeUint64(123));
// create a logic signature
const lsig = algosdk.makeLogicSig(programBytes, args);
const lsigaddr = lsig.address();
const assetID = 12400859; // change to your own assetID
const from = lsigaddr;
const to = from;
console.log(from);
const revocationTarget = undefined;
const closeRemainderTo = undefined;
const note = Uint8Array.from(Buffer.from('0'));
const amount = 0;
const txn = algosdk.makeAssetTransferTxnWithSuggestedParams(
from,
to,
closeRemainderTo,
revocationTarget,
amount,
note,
assetID,
params
);
console.log(txn);
const rawSignedTxn = algosdk.signLogicSigTransactionObject(txn, lsig);
console.log(rawSignedTxn);
const tx = await client.sendRawTransaction(rawSignedTxn.blob).do();
console.log(tx.txId);
})().catch((e) => {
console.log(e);
});
1 Like