script (⏱,💰)

script (⏱,💰)

StarkNet command line transfer method

Today, while doing the StarkNet basecamp assignment, the newly created account B cannot receive ETH, so I want to transfer the ETH from the previously deployed account A to account B.

Both account A and B were created through the command line and cannot be imported into a wallet. They can only be invoked through the command line, SDK, or third-party command line tools to invoke the transfer function of the ETH contract. Using the command line is the simplest method.

Account B was created using the command starknet new_account --account v0.11.0.2. In the ~/.starknet_accounts/starknet_open_zeppelin_accounts.json file, a record will be automatically added as follows:

"v0.11.0.2": {
    "private_key": "0x6c.......c46",
    "public_key": "0x66e22d3fabc4575d48c8b015d830f06dfcd07fe2bcb1b707363cbdee237c2a8",
    "salt": "0x6ebe039e6862dbcc51da66b6729e2ae9c329e6f85d1c7c658055b9ddfdcef93",
    "address": "0xe669f0765742557ea1c44320b5bcf2ca2c5d5725f016a21bb48bcb07932400",
    "deployed": false
}

Similarly, account A can be found, named version_11:

"version_11": {
  "private_key": "0x5a....4ff",
  "public_key": "0x6e5c1e7e741190090f45bd323661203417e7e88c76bf872356d1c84e7462bf2",
  "salt": "0x35ff7c0aeadc5144ea68682a744f4bda3b2b07dadf17ab11dc90ce862fac7c9",
  "address": "0x4f5084d55c9b67e147660e6429a18b3c868c36da70888548b48a43b89ec4cea",
  "deployed": true
}

In the StarkScan browser, account A can be found and the contract address for ETH can be found in the Portfolio section (ETH contract address).

ETH is an upgradable contract, and the Transfer function is not available in the ABI of the proxy contract. The address of the logic contract can be found in the Read/Write Contract section (Implementation address). If the ABI is needed, it can be downloaded from the logic contract's page.

The transfer function can be found on that page, with the recipient parameter as Felt and the amount as Uint256.
transfer

Using the invoke command, the transfer function can be called to complete the transfer.

The transfer command is as follows:
starknet invoke --address 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 --function transfer --inputs 2242186224124962059324130445823883801135621115872240251912124809464678993130 100000000000000000 0 --account version_11

--address is the ETH contract address, and --account is the name of the signed account A.

The parameters in --input need to be converted to Decimal. The recipient is an address and can be converted using Python's int function. The amount is uint256 and requires two felt parameters, with the first being int(ETH amount in e18) and the second being 0.

convert

The transfer is successful.
Transfer success

Next, the account B can be deployed with gas.

Other contract interactions can also be completed using similar methods.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.