I'm facing some issue when sending NFT with solana, Signature verification failed,
const transaction = new Transaction().add(
createTransferInstruction(
fromAccount.address, // ?? Is this suppose be the publicKey or Keypair publicKey
toAccount.address,// ?? Is this wallet address ??
tokenMintAddress, // SLP token PublicKey
1,
[],
TOKEN_PROGRAM_ID
)
)
I'm not really sure what parameters need to pass to this function to verify the signature.
Here is my full snippets
const key = process.env.NEXT_PUBLIC_PRIVATE_KEY;
const myKeypair = Keypair.fromSecretKey(bs58.decode(key));
const tokenMintAddress = new PublicKey('wallet_address'); // NFT tokenAddress
const nftReceiver = new PublicKey('ntf_token_'); // target wallet address
const fromAccount: Account = await getOrCreateAssociatedTokenAccount(
connection,
myKeypair,
tokenMintAddress,
myKeypair.publicKey,
)
const toAccount = await getOrCreateAssociatedTokenAccount(
connection,
myKeypair.publicKey,
tokenMintAddress,
nftReceiver
)
console.log('fromAccount', fromAccount.address.toString())
console.log('toAccount', toAccount.address)
const randKey = Keypair.generate();
const transaction = new Transaction().add(
createTransferInstruction(
fromAccount.address,
toAccount.address,
tokenMintAddress,
1,
[],
TOKEN_PROGRAM_ID
)
)
const {
context: { slot: minContextSlot },
value: { blockhash, lastValidBlockHeight }
} = await connection.getLatestBlockhashAndContext();
const signature = await sendTransaction(transaction, connection, {minContextSlot, maxRetries: 4}).catch(e => console.log('Signature Catch: ', e))
but based on the docs, this is some params but not sure what is the correct value for this
#param source — Source account
#param destination — Destination account
#param owner — Owner of the source account
#param amount — Number of tokens to transfer
#param multiSigners — Signing accounts if owner is a multisig
#param programId — SPL Token program account
#return — Instruction to add to a transaction
Related
I'm trying to sign a transaction on solana with this piece of code:
const txs = [];
const { recentBlockhash, instructions, feePayer } = tx;
const newTx = new SolTransaction({
feePayer,
recentBlockhash,
});
for (const ins of instructions) {
newTx.add(ins);
}
newTx.sign({ publicKey: this._signer.publicKey, secretKey: this._signer.secretKey });
txs.push(newTx);
but for some reason when i sign the transaction i get this error:
Non-base58 character any idea why?
I wrote a function burnSplToken which takes two inputs:
(account(wallet address): string, {account(token address): string, amount: number(token amount)})
I am trying to create a transaction to burn specific amount of tokens. But it's giving me a buffer error at the getOrCreateAssociatedTokenAccount function saying buffer not found error. What am I doing wrong here? I am using react for the frontend.
export const burnSplToken = async (walletAddress, assetAddress) => {
const connection = new Connection(clusterApiUrl("devnet"), "confirmed");
let senderAddress = new PublicKey(walletAddress)
const mintPubkey = new PublicKey(assetAddress.tokenAddress);
let ataSender = await getOrCreateAssociatedTokenAccount(
connection, // connection
senderAddress, // fee payer
mintPubkey, // mint
senderAddress // owner,
);
console.log(`ATASender: ${ataSender}`);
// calculate ATA
let ata1 = await getAssociatedTokenAddress(
mintPubkey, // mint
senderAddress // owner
);
const message = `Sign below to authenticate with Rifters Adventure`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await window.solana.signMessage(encodedMessage, "utf8");
let blockhash = (await connection.getLatestBlockhash('finalized')).blockhash;
let tx = new Transaction().add(
createBurnCheckedInstruction(
ataSender.address, // token account
mintPubkey, // mint
senderAddress, // owner of token account
1e9, // amount, if your deciamls is 8, 10^8 for 1 token
9 // decimals
)
);
tx.recentBlockhash = blockhash;
tx.feePayer = senderAddress
const signedTransaction = await window.solana.signTransaction(tx);
console.log("signedTransaction", signedTransaction);
const signature = await connection.sendRawTransaction(signedTransaction.serialize());
console.log(signature)
}
I'm trying to write an integration test to call a method on a Near Protocol contract.
I've got as far as creating the account object, and now need to set the key pair to be able to make the call.
I can see that I can get the private key value by logging in on the near-cli and getting the key from the .nearcredentials folder. But it seems like I need to encode this before setting the key in the store.
const keyStore = new keyStores.InMemoryKeyStore();
const config = {
keyStore,
networkId: "testnet",
nodeUrl: "https://rpc.testnet.near.org",
};
const near = await connect(config);
const account = await near.account("my_account.testnet");
const keyPair = ???
await keyStore.setKey(config.networkId, "my_account.testnet", keyPair);
const result = await account.functionCall({
contractId: "nft-example.my_account.testnet",
methodName: "nft_metadata"
})
I've figured out how to generate the KeyPair from the private key, full code example is here, but it's basically the first line of the example using the near utils function
const { connect, keyStores, utils, Contract } = require("near-api-js");
const keyPair = new utils.key_pair.KeyPairEd25519(process.env.TEST_ACCOUNT_PRIVATE_KEY);
const keyStore = new keyStores.InMemoryKeyStore();
await keyStore.setKey(networkId, "my_account.testnet", keyPair);
const near = await connect({
keyStore,
networkId,
nodeUrl: "https://rpc.testnet.near.org",
});
const account = await near.account("my_account.testnet");
const contract = new Contract(
account,
'nft-example.my_account.testnet',
{
viewMethods: ['nft_metadata'],
changeMethods: []
}
);
const result = await contract.nft_metadata();
expect(result.spec).toBe("nft-1.0.0");
I'm trying to execute an Pancakeswap swapExactTokensForTokens using ethers.js but i just keep getting the error invalid response - sendTransaction. Unfortunatly the error doesnt contain any more usefull information then that :(
My code:
const provider = new ethers.providers.WebSocketProvider(config.network);
const tradeWallet = ethers.Wallet.fromMnemonic(config.mnemonic);
const account = tradeWallet.connect(provider);
const router = new ethers.Contract(
'0x10ED43C718714eb63d5aA57B78B54704E256024E',
[
'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)',
'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)'
],
account
);
[snip]
var amountIn = ethers.utils.parseUnits('0.001', 'ether');
var tokenIn = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
var tokenOut = '0xd2de3fd31b5c9e1557cf329032615a2870a29ccd';
var gasPrice = '5000000000';
var gasLimit = '231795'
var amounts = await router.getAmountsOut(amountIn, [tokenIn, tokenOut])
const amountOutMin = amounts[1].sub(amounts[1].div(10));
// values at the time where:
// tokenIn: 100000000000000 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c (WBNB)
// tokenOut: 1810636794711288351 0xd2de3fd31b5c9e1557cf329032615a2870a29ccd
var tx = router.swapExactTokensForTokens(
amountIn,
amountOutMin,
[tokenIn, tokenOut],
addresses.recipient,
Date.now() + 1000 * 60 * 3, //10 minutes
{ gasPrice: gasPrice,
gasLimit: gasLimit
}
);
const receipt = await tx.wait();
use 'swapExactTokensForETHSupportingFeeOnTransferTokens',Because your 'tokenOut' token has a tax function
Using AWSMibileHub to set up my backend. Working on an admin page that shows all the users from AWS Cognito.
I’m using ListUsers to get user list and noticed 502 error on the request with a PagenationToken and it seems to be happening randomly.
In CloudWatch shows this error below.
InvalidParameterException: 1 validation error detected: Value 'CAISlAIIARLtAQgDEugBADSdLB5dZXQEaQjoL8y8CE1RGGT3PZ4FpCqxFwJkNuhIeyJAbiI6IlBhZ2luYXRpb25Db250aW51YXRpb25EVE8iLCJuZXh0S2V5IjoiQUFBQUFBQUFCZHM4QVFFQmJBZmU5OFgzUnJTM1BHcnYzVmRiVWNScVdIck82VXFZaTdlZklleVRCSEZsYm1ZN01UVTRPV1k0TVRNdE9UYzVZUzAwWTJKakxUazROekl0TkdRek9UYzROMlpoWmpVM093PT0iLCJwcmV2aW91c1JlcXVlc3RUaW1lIjoxNTQzMDkzODIyNDk5fRogNk7FThSKBOuwQGi DoZBnmNN85UY5oFiSAbHWfOzreY=' at 'paginationToken' failed to satisfy constraint: Member must satisfy regular expression pattern: [\S]+
Does anybody have the same issue or any idea how to fix this issue?
Store the pagination Token in a variable and then add this .replace(/\ /g,'+') to the variable to change the space back to +.
e.g:
const pagination = 'TOKEN FROM COGNITO'.replace(/\ /g,'+')
The pagination_token consists of non alphanumeric characters, so its better to encrypt and decrypt when required.
Encrypt?decrypt utility file
const crypto = require("crypto");
const algorithm = "aes-256-ctr";
const password = "sassed";
class Util {
static encrypt_aes(text) {
let cipher = crypto.createCipher(algorithm, password);
let crypted = cipher.update(text, "utf8", "hex");
crypted += cipher.final("hex");
return crypted;
}
static decrypt_aes(text) {
let decipher = crypto.createDecipher(algorithm, password);
let dec = decipher.update(text, "hex", "utf8");
dec += decipher.final("utf8");
return dec;
}
}
module.exports = Util;
PaginationToken encryption/decription
const Util = require("./utils");
class Users {
static async getUsersAttributes(params) {
let listparams = {
UserPoolId: userPoolID /* required */,
Limit: params.limit || 10,
};
if (params.paginationToken) {
listparams.PaginationToken = Util.decrypt_aes(params.paginationToken);
}
let response = await cognitoISPClient.listUsers(listparams).promise();
response.PaginationToken = Util.encrypt_aes(response.PaginationToken);
return response;
}
}