SethDev
1
// const fs = require('fs');
// const path = require('path');
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 program = 'int 1';
const compiledProgram = await client.compile(program).do();
const programBytes = new Uint8Array(
Buffer.from(compiledProgram.result, 'base64')
);
// create a logic signature
const lsig = algosdk.makeLogicSig(programBytes);
const lsigaddr = lsig.address();
console.log(lsigaddr);
const assetID = 12400859; // change to your own assetID
const params = await client.getTransactionParams().do();
const sender = lsigaddr;
const recipient = lsigaddr;
const revocationTarget = undefined;
const closeRemainderTo = undefined;
const note = new Uint8Array(Buffer.from('Hello World', 'utf8'));
const amount = 0;
// signing and sending "txn" allows sender to begin accepting asset specified by creator and index
const opttxn = algosdk.makeAssetTransferTxnWithSuggestedParams(
sender,
recipient,
closeRemainderTo,
revocationTarget,
amount,
note,
assetID,
params
);
const rawSignedTxn = opttxn.signLogicSigTransactionObject(opttxn, lsig);
const tx = await client.sendRawTransaction(rawSignedTxn).do();
console.log(tx.txId);
})().catch((e) => {
console.log(e);
});
This does not work.
I get this error: TypeError: opttxn.signLogicSigTransactionObject is not a function
fabrice
2
It’s algosdk.signLogicSigTransactionObject
See algosdk
SethDev
3
Is that referring to this?
const rawSignedTxn = algosdk.signLogicSigTransactionObject({txn, lsig})?
SethDev
5
Please I need help with this:
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 program = 'int 1111';
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 params = await client.getTransactionParams().do();
const sender = lsigaddr;
const recipient = sender;
const revocationTarget = undefined;
const closeRemainderTo = undefined;
const note = undefined;
const amount = 0;
const txn = algosdk.makeAssetTransferTxnWithSuggestedParams(
sender,
recipient,
closeRemainderTo,
revocationTarget,
amount,
note,
assetID,
params
);
const rawSignedTxn = algosdk.signLogicSigTransactionObject(txn, lsig);
const tx = await client.sendRawTransaction(rawSignedTxn).do();
console.log(tx.txId);
})().catch((e) => {
console.log(e);
});
I get this error: “TypeError: Argument must be byte array”
SethDev
6
It works when I use an account address with the private key to sign the transaction but throws that error when I use a logicsig
scholtz
7
try
const note = Uint8Array.from(Buffer.from(""));
SethDev
8
After changing it, I still get the same error
SethDev
9
And if I try removing the note field, I get this error message, “Error: genesis hash must be specified and in a base64 string.”
SethDev
10
I have fixed the error after several debugging.
Will drop the code in case anyone experiences something similar for an easy fix.
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);
});