Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
How to pass constant solidity address variable to tests in JS

My constant address is:

const addr = '0xcd3b766ccdd6ae721141f452c550ca635964ce71';

And my solidity contract is as follows -

function temp(address _myAddress) {
    // some code
}

How to pass this constant address to JS tests

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There are three different methods to do this in your test file-

Method 1 :

it ("Method1", async () => {
        const addr = '0xcd3b766ccdd6ae721141f452c550ca635964ce71';
        console.log(addr);
        await contract.temp(addr);
        const userAddress = await contract.getTempAddr(); // say this function exists
        expect(userAddressList).to.equal(addr);
        // Successfully passes address to solidity but gives assertion error (due to checksum error)
    });

Method 2:

it ("Method2", async () => {
        const Web3 = require('web3');
        const web3 = new Web3(Web3.givenProvider);
        const addr = Web3.utils.toChecksumAddress('0xcd3b766ccdd6ae721141f452c550ca635964ce71');
        await contract.temp(addr);
        const userAddress = await contract.getTempAddr();
        expect(userAddressList).to.equal(addr);
    });

Method 3:
Creating directly a wallet

it ("Method3", async () => {
        const addrWallet = new ethers.Wallet('0xcd3b766ccdd6ae721141f452c550ca635964ce71');
        await contract.temp(addrWallet.address);
        const userAddressList = await contract.getTempAddr();
        expect(userAddressList[0]).to.equal(addrWallet.address);
    });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!