0

I'm having issues sending ETH to an extremely basic smart contract. Here's the smart contract code:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;

contract hodl {
  
  uint num;
  uint value;
    
  constructor() {
      num = 69;
      value = 0;
  }
  
  event showNum(uint num);
  event seeSender(address addy, uint value);

  fallback() external payable {
    emit seeSender(msg.sender, msg.value);
    emit showNum(num);
    num += 1;
  }

  function printNum() public returns (uint y){
    emit showNum(num);
    return num;
  }

  function printValue() public returns (uint y){
    return value;
  }

}

Here's the deployment code if it matters (file name is 2_deploy_contract.js):

const hodl = artifacts.require("hodl.sol");

module.exports = function (deployer) {
  deployer.deploy(hodl);
};

Here's the output from my terminal:

truffle(ganache)> c = await hodl.deployed()
undefined
truffle(ganache)> c.sendTransaction({from: ‘0x40Fdb0DceC71c8e3b414FB04351C9eDd45116120’, value: ‘1000000000000000'})
evalmachine.<anonymous>:0
c.sendTransaction({from: ‘0x40Fdb0DceC71c8e3b414FB04351C9eDd45116120’, value: ‘1000000000000000'})
                         

Uncaught SyntaxError: Invalid or unexpected token
truffle(ganache)> 
3
  • In javascript to delimit string you can use single quotes ' or double quotes ". The character you are using isn't the correct one .
    – Ismael
    Nov 30, 2021 at 4:47
  • That doesn't change anything unfortunately Dec 2, 2021 at 1:05
  • If you got the same error it means there is another quote that has to be replaced. If you got a different error then you can edit the question to add it.
    – Ismael
    Dec 2, 2021 at 3:14

2 Answers 2

0

Shouldn't const hodl = require('hodl.sol');

Be:

const hodl = require('hodl');

2
  • I think either one is fine Dec 2, 2021 at 0:56
  • did you try it? cuz you're supposed to import the contract name not the file name Dec 2, 2021 at 1:55
0

So I'm super dumb and realized I wasn't sending enough WEI to notice a change in the accounts value. That was the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.