Search code examples
rpcweb3jsrsk

How to send a web3 transaction from a test account of RSKj regtest blockchain node


I am creating a DApp that connects to a smart contract deployed on a local test RSK blockchain (regtest) run by RSKj Java app. I intend to send transactions via Web3 connected to Metamask. In DApp I am getting the accounts list by sending a Web3 request:

const accounts = await web3.eth.getAccounts()

Further, accounts will contain:

[
  '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
  '0x7986b3DF570230288501EEa3D890bd66948C9B79',
  '0x0a3aA774752ec2042c46548456c094A76C7F3a79',
  '0xCF7CDBbB5F7BA79d3ffe74A0bBA13FC0295F6036',
  '0x39B12C05E8503356E3a7DF0B7B33efA4c054C409',
  '0xc354D97642FAa06781b76Ffb6786f72cd7746C97',
  '0xDEBe71E1dE41Fc77C44Df4b6Db940026E31b0e71',
  '0x7857288e171C6159C5576d1bD9AC40c0c48a771C',
  '0xa4Dea4d5C954f5FD9e87f0e9752911E83a3D18b3',
  '0x09a1edA29F664ac8f68106F6567276dF0C65D859',
  '0xeC4ddeB4380Ad69B3E509BaAd9f158CDF4E4681d'
]

How do I import these accounts (or at least the first one of them) to Metamask in order to send transactions to the smart contract?


Solution

  • The first account from the list is referred as a “cow” seed in this file in RSKj. You can take the corresponding private key from there.

    Do the following:

    1. copy the private key c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4,
    2. open your Metamask browser plugin
    3. select regtest network
    4. import the account
      1. Account icon in the upper right corner
      2. Import account
      3. ‘Paste your private key string here:’
    5. Set the just imported account as an active one
    6. Enjoy sending your transactions