LLC Crowdsale — Full Walkthrough with Truffle Console

This is part 2 of my series in which I show you how to tokenize an LLC in order to raise capital for your business.

The first part walks you through the frontend. Part 2 is for those interested in learning how to execute your contract functions on the backend (e.g. withdrawing funds from the crowdsale, whitelisting members, pausing the sale, etc.)

Tools used:

First, you need to have node installed. Then you must install Truffle. Truffle is notoriously tricky to install because it’s not compatible with all versions of node.

With Homebrew for Mac it’s simple:

But, sometimes the latest version won’t be compatible with Truffle. So instead, I would recommend following this tutorial to install the node version manager(nvm), which will allow you to download and manage several versions of node.

Once nvm is installed, you should be able to change versions with this command:

For example:

Open VS Code or your favorite editor. Open a new terminal and then:

This will create a new truffle project, complete with a truffle-config.js file, a Migrations.Sol contract, and a deploy script ready to go.

Alternatively, you can clone my git repo for the project:

But if you’re building from scratch then there are a few other dependencies you need to install:

Before you launch the truffle console, run npm install one more time just to make sure all the modules you need are set up. You should see a “node_modules” folder in your explorer.

Next, you obviously need to add your Solidity contracts to the “contracts” folder. Again, if you’re building from scratch, just copy and paste each one into a new file, along with the deploy script.

In the truffle-config.js file, you need to set up an Infura account. In your Settings, select the dropdown and choose Rinkeby network. Then copy

Your mnemonic is the twelve word password for your Metamask wallet. Put it in your .env file like so:

Run:

Then migrate your contracts:

Start the console:

If done successfully, it should look like this:

Check to see if your Rinkeby test account is linked:

In the next part, we will work directly with an instance of your deployed Solidity contract.

If not:

You can then access the properties of your token:

Create the instances of your Solidity contracts:

You can do other cool things like check the balance of your account:

Create an instance of your token contract:

If done successfully, Token.networks[networkId].address should return the same value as token.address.

Create an instance of your crowdsale:

If done correctly, the contract should show up in the console. You can look over it to view the functions you can access, the same way you would using something like Remix IDE.

For an example of a call function. Let’s call weiRaised:

Access the variable:

It should show how much the crowdsale contract was funded.

Now, let’s try a send function. This will cost us some gas, so make sure you’ve got some test ETH in your account. The crowdsale contract has a buyTokens function. Let’s try that one:

transferAmount should be a small number if you don’t have that much ETH. Then:

Note: Transactions are performed in wei. 1 ETH = 1*10¹⁸ wei

If the transaction was successful, you should see the transaction hash, the “from” wallet, the contract address, among a lot of other bits of info. Check Rinkeby Etherscan with the transaction hash to verify.

Lastly, check how many of your new token you have in your wallet:

That’s it! You know know how to operate your crowdsale directly from Truffle Console! If the tutorial was still hard to follow, I’ve got a full walkthrough video on my channel here.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TechJD

Law, programming, and everything in-between! Coming up with fun coding projects with real-world application.