Closed Lukols-Dev closed 7 months ago
Its my contract:
//SPDX-License-Identifier: MIT pragma solidity ^0.8.9;
import {AxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol"; import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol"; import {IERC20} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol"; import {IAxelarGasService} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
/**
@notice Send a token along with an Axelar GMP message between two blockchains */ contract CallContractWithToken is AxelarExecutable { IAxelarGasService public immutable gasService;
event Executed();
/*
/**
address tokenAddress = gateway.tokenAddresses(symbol); IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount); IERC20(tokenAddress).approve(address(gateway), amount); bytes memory payload = abi.encode(destinationAddresses); gasService.payNativeGasForContractCallWithToken{value: msg.value}( address(this), destinationChain, destinationAddress, payload, symbol, amount, msg.sender ); gateway.callContractWithToken(destinationChain, destinationAddress, payload, symbol, amount); }
/**
uint256 sentAmount = amount / recipients.length; for (uint256 i = 0; i < recipients.length; i++) { IERC20(tokenAddress).transfer(recipients[i], sentAmount); } emit Executed(); }
// Funkcja sendToken do wysyłania określonej ilości tokenów do określonego adresu na łańcuchu docelowym function sendToken( string memory destinationChain, string memory destinationAddress, string memory symbol, uint256 amount ) external payable { require(msg.value > 0, "Gas payment is required");
address tokenAddress = gateway.tokenAddresses(symbol); require( IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount), "Token transfer failed" );
// Zatwierdź gateway Axelar do użycia tokenów w imieniu tego kontraktu require(IERC20(tokenAddress).approve(address(gateway), amount), "Token approve failed");
// Przygotuj payload jako adres docelowy w formacie bytes bytes memory payload = abi.encode(destinationAddress);
// Zapłać za gas w sieci źródłowej i wywołaj callContractWithToken na gateway Axelar gasService.payNativeGasForContractCallWithToken{value: msg.value}( address(this), destinationChain, destinationAddress, payload, symbol, amount, msg.sender );
gateway.callContractWithToken(destinationChain, destinationAddress, payload, symbol, amount); } }
and its my script to send token Sepolia->Mumbai:
import { ethers } from "hardhat"; import { AxelarQueryAPI, Environment, EvmChain, GasToken } from "@axelar-network/axelarjs-sdk";
async function main() { const destinationAdress = "0x22BfB01f2831A717DFc8053Fd29F45EDaDff9960"; //deployed contract in Mumbai const destinationChain = "Polygon"; // Nazwa łańcucha docelowego const adressess = ["0x1e147BA822892748ED2A8952C582e4da4A3200ff"]; //wallet address const symbol = "aUSDC"; // Symbol tokena, który chcesz wysłać const amount = ethers.utils.parseUnits("1", 18); // Łączna ilość tokenów do wysłania, pamiętaj o dostosowaniu do liczby miejsc dziesiętnych dla USDC
// Pobranie instancji Twojego kontraktu const contract = await ethers.getContractAt( "CallContractWithToken", "0xe1C0C45A4B2C80D266e39751ECfEaEa7065ca963", //Deployed contract in Sepolia );
// Szacowanie Gas przed wysłaniem const api = new AxelarQueryAPI({ environment: Environment.TESTNET });
const estimatedGas = await api.estimateGasFee( "ethereum-sepolia", EvmChain.POLYGON, GasToken.ETH, 700000, 2, );
console.log("Estimate gas: ", estimatedGas);
const sendTx = await contract.sendToMany( destinationChain, destinationAdress, adressess, symbol, amount, { value: BigInt(3000000), gasLimit: 200000, }, ); await sendTx.wait();
console.log(Initialize: ${sendTx.hash}
);
}
main().catch((error) => { console.error(error); process.exit(1); });
Thanks for creating an issue. Is this the complete contract code? It looks like there is no _executeWithToken function. Also, I can see you have sendToMany and sendToken. Which one are you using?
I would like to use sendToMany. is placed _executeWithToken
unless you want it to look different, the contract is what was in example-web for call-contract-with-token
Looking at the execution script, This ethers.utils.parseUnits("1", 18);
should be ethers.utils.parseUnits("1", 6);
since its aUSDC or you use ethers.utils.parseEther("1")
.
Also, you might want to remove the gasLimit
and then the value
should be estimatedGas
not BigInt(3000000)
then I am making changes, thank you I'll let you know if it worked
import { ethers } from "hardhat";
//Deploy for Poligon and Sepolia
async function main() { const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const Contract = await ethers.getContractFactory("CallContractWithToken"); const contract = await Contract.deploy( "0xBF62ef1486468a6bd26Dd669C06db43dEd5B849B", "0xbE406F0189A0B4cf3A05C286473D23791Dd44Cc6", ); //From here https://docs.axelar.dev/resources/contract-addresses/testnet
console.log("Contract address:", contract.address); }
main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });
Estimate gas: 104766895062823
Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted: arithmetic underflow or overflow", method="estimateGas", transaction={"from":"0x1e147BA822892748ED2A8952C582e4da4A3200ff","to":"0xe4d72642C95a93025dA2cc4ad10208697FCAb243","value":{"type":"BigNumber","hex":"0x5f48f1907f27"},"data":"0xfbd9497b00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000f42400000000000000000000000000000000000000000000000000000000000000007506f6c79676f6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a3078463938416265633030323534424366313946663238313545643963343639333946313863303964430000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000001e147ba822892748ed2a8952c582e4da4a3200ff00000000000000000000000000000000000000000000000000000000000000056155534443000000000000000000000000000000000000000000000000000000","accessList":null}, error={"name":"ProviderError","_stack":"ProviderError: execution reverted: arithmetic underflow or overflow\n at HttpProvider.request (/Users/lukols/Documents/Programowanie/Blockchain/hardhat-version/node_modules/hardhat/src/internal/core/providers/http.ts:90:21)\n at processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async EthersProviderWrapper.send (/Users/lukols/Documents/Programowanie/Blockchain/hardhat-version/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)","code":3,"_isProviderError":true,"data":"0x4e487b710000000000000000000000000000000000000000000000000000000000000011"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.2)
at Logger.makeError (/Users/lukols/Documents/Programowanie/Blockchain/hardhat-version/node_modules/@ethersproject/logger/src.ts/index.ts:269:28)
at Logger.throwError (/Users/lukols/Documents/Programowanie/Blockchain/hardhat-version/node_modules/@ethersproject/logger/src.ts/index.ts:281:20)
at checkError (/Users/lukols/Documents/Programowanie/Blockchain/hardhat-version/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:78:20)
at EthersProviderWrapper.
async function main() { const destinationAdress = "0xF98Abec00254BCf19Ff2815Ed9c46939F18c09dC"; //deployed contract in Mumbai const destinationChain = "Polygon"; // chain name const adressess = ["0x1e147BA822892748ED2A8952C582e4da4A3200ff"]; //wallet address const symbol = "aUSDC"; // token symbol const amount = ethers.utils.parseUnits("1", 6);
// Get contract const contract = await ethers.getContractAt( "CallContractWithToken", "0xe4d72642C95a93025dA2cc4ad10208697FCAb243", //Deployed contract in Sepolia );
// Estimate Gas const api = new AxelarQueryAPI({ environment: Environment.TESTNET });
const estimatedGas = await api.estimateGasFee( "ethereum-sepolia", EvmChain.POLYGON, GasToken.ETH, 700000, 2, );
console.log("Estimate gas: ", estimatedGas);
const sendTx = await contract.sendToMany( destinationChain, destinationAdress, adressess, symbol, amount, { value: estimatedGas.toString(), }, ); await sendTx.wait();
console.log(Initialize: ${sendTx.hash}
);
}
main().catch((error) => { console.error(error); process.exit(1); });
On sepolia I don't have aUSDC, where can I get it, there are no assets in the testnet documentation
You can get it on our discord in the faucet channel. By specifying !faucet <network> <your address>.
ok, I take but where to find the address of the aUSDC token for testnet, there were videos on youtube that for testnet assets are there, in fact there is no such data in the Axelar documentation?
Hey @Lukols-Dev, you can find the aUSDC address for testnet here: https://docs.axelar.dev/resources/contract-addresses/testnet#assets
Hi,
I dont have reason. I have error:
reason: 'transaction failed', code: 'CALL_EXCEPTION',
I want to use sandToMany to send tokens (aUSDC) between Sepolia -> Mumbai. What could I be doing wrong?
const sendTx = await contract.sendToMany( destinationChain, //Poligon destinationAdress, //deployed contract in Mumbai adressess, //wallet addres in [] symbol, // "aUSDC" amount, //ethers.utils.parseUnits("1", 6) { value: ethers.utils.parseEther("0.01"), gasLimit: 200000, }, );