ink icon indicating copy to clipboard operation
ink copied to clipboard

Unable to deploy Ink smart contract to the local node.

Open Subway2023 opened this issue 3 months ago • 4 comments

Reference link: creating-an-ink-project, hardhat-deployment Problem: unable to successfully deploy the contract following the documentation. Aim: deploy the Ink contract with a Solidity-compatible ABI and invoke it for differential testing

ink smart contract project

cargo contract new flipper

Change abi = "ink" to abi = "sol" in Cargo.toml

cargo contract build

hardhat project

mkdir hardhat-example
cd hardhat-example
npm init -y

npm install --save-dev @parity/hardhat-polkadot

npx hardhat-polkadot init
npm install

hardhat.config.js(the document does not include global.WebSocket = require("ws");, which will cause an error.)

global.WebSocket = require("ws"); 

require('@nomicfoundation/hardhat-toolbox');
require('@parity/hardhat-polkadot');

module.exports = {
  // ... other config
  networks: {
    hardhat: {
      polkavm: true,
      nodeConfig: {
        nodeBinaryPath: '/mnt/sdd1/sbw/sol2rust/tool/ink-node-linux/ink-node',
        rpcPort: 8000,
        dev: true,
      },
      adapterConfig: {
        adapterBinaryPath: '/mnt/sdd1/sbw/sol2rust/tool/ink-node-linux/eth-rpc',
        dev: true,
      },
    },
    localNode: {
      polkavm: true,
      url: `http://127.0.0.1:8545`,
    },
  },
};

scripts/deploy.js

const hre = require('hardhat');
const { join } = require('path');
const { readFileSync } = require('fs');

// Import the ABI of the contract from the flipper_evm.json file.
const abi = require("/mnt/sdd1/sbw/sol2rust/test/flipper/target/ink/flipper.json").output.abi;
// console.log("abi",abi)

async function main() {
    const [deployer] = await hre.ethers.getSigners();

    // Fetch the bytecode of the contract.
    const bytecodePath = join("/mnt/sdd1/sbw/sol2rust/test/flipper/target/ink/flipper.polkavm");
    const bytecode = `0x${readFileSync(bytecodePath).toString('hex')}`;

    const flipper = new hre.ethers.ContractFactory(abi, bytecode, deployer);

    // Deploy the contract with the constructor arguments.
    const contract = await flipper.deploy(true);
    await contract.waitForDeployment();
    
    // Get the address of the deployed contract.
    const address = await contract.getAddress();
    console.log(`Contract deployed at: ${address}`);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

start node

npx hardhat node

deploy

first error

npx hardhat run scripts/deploy.js --network localNode --no-compile
ProviderError: Transaction Already Imported
    at HttpProvider.request (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/hardhat/src/internal/core/providers/http.ts:116:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HardhatEthersSigner.sendTransaction (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/@nomicfoundation/hardhat-ethers/src/signers.ts:181:18)
    at ContractFactory.deploy (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/ethers/src.ts/contract/factory.ts:111:24)
    at main (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/scripts/deploy.js:19:22)

another error

if i modify url: http://127.0.0.1:8545 to url: http://127.0.0.1:8000 in hardhat.config.js, there is another error

npx hardhat run scripts/deploy.js --network localNode --no-compile
ProviderError: Method not found
    at HttpProvider.request (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/hardhat/src/internal/core/providers/http.ts:116:21)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at getSigners (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/node_modules/@nomicfoundation/hardhat-ethers/src/internal/helpers.ts:46:16)
    at main (/mnt/sdd1/sbw/sol2rust/test/hardhat-example/scripts/deploy.js:10:24)

Subway2023 avatar Sep 03 '25 11:09 Subway2023

Hi! I’m the author of this tutorial https://use.ink/tutorials/ethereum-compatibility/hardhat-deployment .

I can reproduce your issue. I’m not yet sure what changed that prevents deploying an ink! contract with Solidity metadata, whether it’s in ink-node or due to recent changes in hardhat-polkadot.

Have you tried deploying the example Solidity contract from the docs? https://docs.polkadot.com/develop/smart-contracts/dev-environments/hardhat/#set-up-hardhat. I tried and hit an issue as well: https://github.com/paritytech/hardhat-polkadot/issues/306

AlexD10S avatar Sep 08 '25 10:09 AlexD10S

@AlexD10S Could you try deploying the contract via e.g. polkadot-js? It's not a nice API, but this will already tell you if there's a more general error.

Image

cmichi avatar Sep 12 '25 20:09 cmichi

@AlexD10S Could you try deploying the contract via e.g. polkadot-js? It's not a nice API, but this will already tell you if there's a more general error.

Deployment works with PolkadotJS on v6.0.0-alpha.4: Image Hardhat still fails with the same issue as @Subway2023. @davidsemakula , any suggestions on what to try next?

AlexD10S avatar Sep 19 '25 08:09 AlexD10S

Alright, looking into this

davidsemakula avatar Sep 19 '25 09:09 davidsemakula