I’m new to using Ethersjs and I want to create a function that transfers PIXEL token from one wallet to another.I have searched somewhere but I can’t find any inform about my error. I even dont’t know where code line get error, please figure out to me what I’ve wrong. thanks
This is my code
const { ethers } = require("ethers");
const apiKey = "YA0OR4gRypGADI7AV8OGf5qp9izvDoGC";
const pixelContractAddress = "0x3429d03c6F7521AeC737a0BBF2E5ddcef2C3Ae31";
// Initialize the Provider
const provider = new ethers.JsonRpcProvider(
"https://api-gateway.skymavis.com/rpc?apikey=" + apiKey
);
async function sendPIXEL(privateKey, toAddress, amount) {
// Create a wallet from the private key
const wallet = new ethers.Wallet(privateKey, provider);
const pixelToken = new ethers.Contract(
pixelContractAddress,
require("./pixelABI.json"),
wallet
);
// Convert amount to Wei
const weiAmount = ethers.parseEther(amount);
// Create a transaction object
const transaction = {
to: toAddress,
value: weiAmount,
};
// Sign and send the transaction
const transactionResponse = await pixelToken.transfer(transaction);
console.log(transactionResponse);
}
// Call the sendPIXEL function with the necessary parameters
const privateKey =
"my private key";
const toAddress = "0xeb0d63d9fa69c58b019dbad9c7e3aebcc3e6cbf8";
const amount = "0.1"; // Amount of RON to send
sendPIXEL(privateKey, toAddress, amount);
and when I run it throw me this error
C:UsersDoan ThangDownloadschilatestappnode_modulesetherslib.commonjsutilserrors.js:129
error = new Error(message);
^
Error: no matching fragment (operation="fragment", info={ "args": [ { "to": "0xeb0d63d9fa69c58b019dbad9c7e3aebcc3e6cbf8", "value": 100000000000000000 } ], "key": "transfer" }, code=UNSUPPORTED_OPERATION, version=6.12.1)
at makeError (C:UsersDoan ThangDownloadschilatestappnode_modulesetherslib.commonjsutilserrors.js:129:21)
at assert (C:UsersDoan ThangDownloadschilatestappnode_modulesetherslib.commonjsutilserrors.js:149:15)
at getFragment (C:UsersDoan ThangDownloadschilatestappnode_modulesetherslib.commonjscontractcontract.js:193:31)
at Proxy.transfer (C:UsersDoan ThangDownloadschilatestappnode_modulesetherslib.commonjscontractcontract.js:257:26)
at sendPIXEL (C:UsersDoan ThangDownloadschilatestapptest.js:31:48)
at Object.<anonymous> (C:UsersDoan ThangDownloadschilatestapptest.js:41:1)
at Module._compile (node:internal/modules/cjs/loader:1241:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1295:10)
at Module.load (node:internal/modules/cjs/loader:1091:32)
at Module._load (node:internal/modules/cjs/loader:938:12) {
code: 'UNSUPPORTED_OPERATION',
operation: 'fragment',
info: {
key: 'transfer',
args: [
{
to: '0xeb0d63d9fa69c58b019dbad9c7e3aebcc3e6cbf8',
value: 100000000000000000n
}
]
},
shortMessage: 'no matching fragment'
}
Node.js v20.9.0
my pixelABI.json:
[
{
"inputs": [
{ "internalType": "string", "name": "name", "type": "string" },
{ "internalType": "string", "name": "symbol", "type": "string" },
{ "internalType": "uint256", "name": "totalSupply_", "type": "uint256" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "spender",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{
"internalType": "uint256",
"name": "subtractedValue",
"type": "uint256"
}
],
"name": "decreaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "addedValue", "type": "uint256" }
],
"name": "increaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
}
]
version of etherjs is 6.12.1 and nodejs is 20.9.0
Thanks a lot