# Interacting with upgradeable ERC20 using geth

**URL:** <https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328>\
**Category:** Support\
**Tags:** erc20, proxies\
**Created:** [January 8, 2021, 12:12am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328 "2021-01-08T00:12:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![beck1234](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@beck1234](https://forum.openzeppelin.com/u/beck1234)\
**Post date:** [January 8, 2021, 12:12am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/1 "2021-01-08T00:12:15Z")

</div>

I am trying to interact with an erc20 token (contains proxies) using geth.

**💻 Environment**

Geth/v1.9.24

**📝Details**

This is the process I follow when interacting with a regular erc20 token without proxies (ex. usdt):

1. Create a .js file similar to below:

> var usdtContractToken = eth.contract([{...usdtABI...}])  
> var usdtContractAddress = "0xdAC17F958D2ee523a2206206994597C13D831ec7";  
> var usdt = usdtContractToken.at(usdtContractAddress);

1. Preload geth with the above .js file using command:

> geth attach --preload \< pathToJsFile \>

1. Then interact with the erc20 token in geth console:

> ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/6/6da103e1d09a957dec1850790488d3876fbf3c96.png)

**I am facing difficulties with using the above methodology when interacting with erc20 tokens that involve proxy contracts** (ex. usdc, which uses _OpenZeppelin's Unstructured Storage proxy pattern_).

I am not sure what are the additional steps required to configure this setup.

Below is the .js file I am using to preload into geth:

**🔢 Code to reproduce**

> // proxy  
> var usdcProxyContractToken = eth.contract([{...usdcProxyABI...}]);  
> var usdcProxyContractAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";  
> var usdcProxy = usdcProxyContractToken.at(usdcProxyContractAddress);
> 
> // implementation  
> var usdcImpContractToken = eth.contract([{...usdcImpABI...}]);  
> var usdcImpContractAddress = "0xB7277a6e95992041568D9391D09d0122023778A2";  
> var usdcImp = usdcImpContractToken.at(usdcImpContractAddress);

**Output from geth console:**

> usdcProxy.admin()  
> Error: execution reverted  
> at web3.js:6347:37(47)  
> at web3.js:5081:62(37)  
> at web3.js:4102:36(54)  
> at web3.js:4227:60(38)  
> at :1:1(2)

> usdcImp.name()  
> Error: invalid address  
> at web3.js:3930:11(47)  
> at web3.js:3756:41(16)  
> at web3.js:5025:37(8)  
> at web3.js:5024:12(13)  
> at web3.js:5050:34(20)  
> at web3.js:5075:39(15)  
> at web3.js:4137:41(57)  
> at web3.js:4223:75(24)  
> at :1:1(2)

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [January 8, 2021, 1:02am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/2 "2021-01-08T01:02:26Z")

</div>

Hi @beck1234,

Welcome to the community 👋

To interact with an upgradeable ERC20, you should just be able to use the ABI of the ERC20 and the address of the proxy contract.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [January 12, 2021, 5:56am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/4 "2021-01-12T05:56:08Z")

</div>

Hi @beck1234,

I wanted to check that you were able to interact with the token?

---

<div class="post-metadata">

**Author:** ![beck1234](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@beck1234](https://forum.openzeppelin.com/u/beck1234)\
**Post date:** [January 12, 2021, 9:49pm UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/5 "2021-01-12T21:49:23Z")

</div>

Hi @abcoathup! No luck yet with using the ABI of the ERC20 and the address of the proxy contract as you mentioned above.

I've tried on both geth v1.9.24 and v1.9.25

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/6/6500edeab18eb95de9161900679b30e0891d24f3.png)

Preload above file to geth:

> geth attach --preload pathToJsFile

Geth output:

> usdc.name  
> function()

> usdc.name()  
> Error: invalid address  
> at web3.js:3930:11(47)  
> at web3.js:3756:41(16)  
> at web3.js:5025:37(8)  
> at web3.js:5024:12(13)  
> at web3.js:5050:34(20)  
> at web3.js:5075:39(15)  
> at web3.js:4137:41(57)  
> at web3.js:4223:75(24)  
> at :1:1(2)

Proxy: [https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#code](https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#code)  
Implementation: [https://etherscan.io/address/0xb7277a6e95992041568d9391d09d0122023778a2#code](https://etherscan.io/address/0xb7277a6e95992041568d9391d09d0122023778a2#code)

Please let me know if there are any additional steps that I'm missing.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [January 13, 2021, 9:05am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/6 "2021-01-13T09:05:04Z")

</div>

HI @beck1234,

I haven’t interacted via geth before.

I created a simple script to interact via Alchemy, though you could modify to use a local node.

First I obtained an ERC20 artifact (though you could just use the ABI) from OpenZeppelin Contracts

```auto
$ npm i @openzeppelin/contracts
$ mkdir -p build/contracts/
$ cp node_modules/@openzeppelin/contracts/build/contracts/* build/contracts/

```

Then I installed web3 and the OpenZeppelin Contract Loader (for convenience)

```auto
$ npm i web3
$ npm i @openzeppelin/contract-loader

```

## index.js

Interact using ERC20 and the address of the proxy

```auto
// scripts/index.js
const Web3 = require('web3');
const { setupLoader } = require('@openzeppelin/contract-loader');

const { alchemyApiKey, mnemonic } = require('../secrets.json');

const HDWalletProvider = require('@truffle/hdwallet-provider');

const provider = new HDWalletProvider(mnemonic, `https://eth-mainnet.alchemyapi.io/v2/${alchemyApiKey}`);

async function main() {
  // Set up web3 object
  const web3 = new Web3(provider);

  // Set up a web3 contract, representing a deployed ERC20, using the contract loader
  const address = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
  const loader = setupLoader({ provider: web3 }).web3;
  const token = loader.fromArtifact('ERC20', address);

  // Retrieve accounts
  const accounts = await web3.eth.getAccounts();

  console.log(`Account: ${accounts[0]}`);

  // Call the deployed token contract
  const name = await token.methods.name().call();
  const symbol = await token.methods.symbol().call();
  const decimals = await token.methods.decimals().call();
  const totalSupply = await token.methods.totalSupply().call();
  console.log(`${name} (${symbol}) - Decimals:${decimals} Total Supply:${totalSupply}`);

  // At termination, `provider.engine.stop()' should be called to finish the process elegantly.
  provider.engine.stop();
}

main();

```

## Run

```auto
$ node scripts/index.js
Account: 0xEce6999C6c5BDA71d673090144b6d3bCD21d13d4
USD Coin (USDC) - Decimals:6 Total Supply:4750520962337187

```

---

<div class="post-metadata">

**Author:** ![beck1234](https://avatars.discourse-cdn.com/v4/letter/b/f6c823/32.png) [@beck1234](https://forum.openzeppelin.com/u/beck1234)\
**Post date:** [January 21, 2021, 7:52pm UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/7 "2021-01-21T19:52:37Z")

</div>

@abcoathup Thank you for all the help. I was able to leverage the above scripts to run against my local geth node. It is weird that the same method doesn’t work when interacting directly through geth. I’ll post any updates/progress on it here.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [January 22, 2021, 2:59am UTC](https://forum.openzeppelin.com/t/interacting-with-upgradeable-erc20-using-geth/5328/8 "2021-01-22T02:59:38Z")

</div>

Hi @beck1234,

Glad you can interact now. Updates are appreciated for anyone in future coming across this topic.
