3

I've started working from the drizzle box and can access functions within contracts, but if I want to give an allowance to a contract address so it can use users tokens how can I give the correct address? drizzleOptions contains contracts which have addresses per network but I don't think I can figure out which network is current without a web3 instance, there must be a simple way though to get the address of a contract on the current network?

2

you will need to access the drizzle context object, in the react component. I assume you are working on the 'Home.js' component.

For example:

this.drizzle = context.drizzle

in the constructor of the component and see https://github.com/trufflesuite/drizzle-react/issues/22,

Once you have that working then,

this.drizzle.contracts.TutorialToken.address or equivalently

context.drizzle.contracts.TutorialToken.address should return the address of the network, however, since I am no expert in react, there may be a better approach.

|improve this answer|||||
0

The address is part of the contract API that is loaded together with the drizzle option

So when you just console.log(drizzle) there is the solution. You can view the address directly in you Chrom-Browser when openening the dev tools -> console

Let's assume your contact name is SimpleToken, then

drizzle.contracts.SimpleToken.address hold the contract address

make sure that before you using this, drizzle.contracts.SimpleToken.address is in sync. Otherwise you will get undefined as a return value or an fat red error on you chrome console.

Hope this helps

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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