Smart Contracts

Updating Solidity code and Testing a Smart Contract

Books on the Blockchain

Publica Self Publishing

Goodbye Contracting

Hello brave new old world...

Ruby-Selenium Webdriver

In under 10 Minutes

%w or %W? Secrets revealed!

Delimited Input discussed in depth.

Wednesday, 3 July 2019

Ethereum - Updating and Testing a Raffle Smart Contract

This article is also available on Kauri (Ropsten Testnet).

Over on the Bitfalls website there’s a couple of great tutorials(1) for learning Solidity and Ethereum. The tutorials guide readers through the making of a Raffle. Now, the code is not meant to be bullet proof, but as a software tester by day the ‘gaps’ piqued my interest.

In this post I’m going to do two things; firstly provide a few updates to the code readers pointed out or that have become the more current way of doing things since Solidity version updates and secondly, to execute the code in the online tool, Remix, so we can see how it actually runs.

Naturally, the below makes more sense if you’ve either worked through the tutorials, will do or have just grabbed the code. Let’s crack on.

Code Updates
Firstly, let’s look at what needs a refresh since Bruno wrote the original articles. Open up the Blocksplit.sol file you’ve been working on. You can always get the completed script from their GitHub repository

Review the code for the randomGen() function from their last tutorial:

function randomGen() constant internal returns (uint256 randomNumber) { 
uint256 seed = uint256(block.blockhash(block.number - 200)); return(uint256(keccak256(block.blockhash(block.number-1), seed )) % players.length);

In here we can see the '… block.blockhash(block.number …' construct, this needs to be changed to read '… blockhash(block.number …'.

Additionally, the last line of the randomGen() function should be changed to use `abi.encodePacked` and the trailing space after seed removed. It will look like this:

return(uint256(keccak256(abi.encodePacked(blockhash(block.number-1), seed))) % players.length);

This will give a final code block for the randomGen() function of:

function randomGen() internal view returns (uint256 randomNumber) {
uint256 seed = uint256(blockhash(block.number - 200)); return(uint256(keccak256(abi.encodePacked(blockhash(block.number-1), seed))) % players.length);

One final change just so we don’t lose any test Ether is to change the address public charity to be one of your test accounts, make it the one you deploy the contract under. Account set-up is discussed next.

address public charity = put-the-full-address-here-for-your-test-acccount;

One last thing is to change the ‘Unix epoch’ time in the draw() function to something in the near past if it’s very current.

Set-up the Testing Environment
There’s a few things we need to have in place to test this contract effectively:
  • MetaMask
  • Three Ethereum Accounts
  • Remix open in a browser window
  • The updated contract code ready to deploy
Make sure the MetaMask browser extension is running in either of Brave(2) or Chrome.

We’ll need to have three Ethereum accounts available to us via MetaMask – one to act as the contract owner and two additional ones to act as the players. If you’ve not done so, read the Bitfalls MetaMask article that explains how to set up MetaMask and add accounts. You’ll need to get some free Ether from one of the faucet sites in order to play the raffle.

Remix is a free browser-based IDE for writing smart contracts in Solidity, then compiling and deploying them. It’s available at

Compile and Execute the Contract Code
The Remix UI was updated mid 2019 so may have a different look compared to other tutorials you’ve worked through - be sure to select ‘Solidity’ under the Environments section of the Home page before you start.

To the top-left, change the Compiler version to read 0.4.26+commit.4563 as from version 0.5.0 there were breaking changes to the Solidity codebase. This is also above the 0.4.20 compiler version we stated in the contract code, so the code will compile just fine.

Choose the Solidity environment and Compiler version

In Remix, click on the ‘File explorers’ icon, create a new file and call it 'Blocksplit.sol', then paste the updated contract code into the file and save it.

Create a new file for the contract code

Now click on the ‘Solidity compiler’ icon and hit ‘Compile Blocksplit.sol’

Compile the contract code

Finally, click the ‘Deploy & Run Transactions’ icon, we’ll use this tab to deploy and test our contract. We’ll deploy to the Ropsten test network and to do so we need to change a few things before we hit Deploy.
  • In the ‘Environment’ field select 'Injected Web3' from the dropdown
  • In MetaMask, switch to the ‘Ropsten Test Network’
  • Also in MetaMask, select the account you have chosen as the contract owner account 
Now hit the orange ‘deploy’ button to deploy the contract to Ropsten, accepting the MetaMask transaction window when it pops-up. This is charging the cost of writing to the blockchain.

Deploy the contract to Ropsten

Check the Deployed Contract and Interface
Now we’ve deployed the contract we’ll have a set of buttons that provide an interface to the contract elements, shown under ‘Deployed Contracts’. Click the arrow next to the contract name to show the set of buttons that give us an interface to the contract.

View the contract elements

Next to the contract name is also the contract address that can be copied and searched for on Etherscan against the Ropsten network. Copy the address shown and look up the Etherscan record. Between Etherscan and MetaMask we can readily see how the transaction details match up.

Matching transaction details

We can see that the ‘From’ address, Contract Creator address and the address we used in MetaMask all match. This shows us how organisations can deploy a contract, then use the msg.sender = owner code pattern to assign the ability to perform certain actions only to a given address; in this case the one that deployed the contract.

As a reminder, blue buttons read data and so are free of Gas, whereas orange buttons write data to the blockchain and so will cost us Gas.

Click on the blue ‘charity’ button and you’ll see a) no MetaMask window as we don’t need to pay anything and b) the address we assigned to the `address public charity` variable. Note the contract value is showing as ‘0 Ether’ as no raffle monies have been transacted yet.

Play the Raffle
Ordinarily, the public raffle elements we can get to would be wrapped in a Web3.js enabled webpage, using the ABI file, to give us a smart interface. However, for testing, the Remix interface is good enough.

Player One Plays
To play we need to switch to an alternate account in MetaMask, so we’re acting like the raffle’s Player One and not the owner. Open MetaMask and switch accounts now, that same account will be shown in Remix in the ‘Account’ field.
  • in the ‘Value’ field enter 0.1 and make sure ‘ether’ is selected
  • in the field next to the ‘play’ button, paste the address you’re using as Player One
  • hit the ‘play’ button and accept the MetaMask prompt to pay the fee plus gas
After a few seconds MetaMask will bring up a prompt stating the transaction went through. If we check the contract again on Etherscan, we’ll see it now has a second transaction worth 0.1 ETH from the address we’re using for Player One.

Player One Played

If you now enter '0' in the field next to ‘players’ it will return the address of Player One. This is because we declared address[] public players; at the start of our contract then players.push(_participant); in the play() function - which takes an address (as we tested above), then pushes it onto the players array.

A Quick Sanity Test
Something we can test now is clicking on the ‘draw’ button. The code here is that we can only run a draw if the number of winners is less than 2: require (winners.length < 2, "");. This is interesting as when we click ‘draw’ now it should work and indeed it does. If we enter `0` in the field next to the ‘winners’ button it will return the address of Player One.

It may be that we should change this code in two ways:
  • Change draw() to Require the msg.sender to be the owner of the contract so not just anyone can call the function
  • Set a Require of players.length == 2 to ensure two players are needed for a draw to happen
Player Two Plays
To play a second player is just like playing the first. Switch accounts, set the value to 0.1 ETH, add your Player 2 address into the ‘play’ field and hit ‘play’ as before.

Now in Etherscan we can see:
  • two transactions of 0.1 ETH which are the raffle ‘plays’
  • one transaction between these that are the possibly unwanted pressing of ‘draw’ by a player
Two Plays and one Draw

Both of the above can be proven using Etherscan’s logs:
  • Click on the ‘Txn hash’ for the draw (0 ETH transaction)
  • At the bottom of the page that opens, click on ‘Click to see More’
  • Under ‘Input Data’ check to see it says ‘Function: draw() ***’ 

Draw made by Player One

Repeat the steps above to check one of the Plays made by either player.

Play made by a Player 

However, we may have another potential issue. In the draw() function we have the line of players.length--; which with the line of code above it is a way to remove the winner from the list of players (so they don’t become winner number 2 as well as winner number 1, fair enough). We can test this too by entering a '0' or a '1' in the field next to ‘players’ and seeing what’s returned. We expect two player’s addresses but for index '1' we should get ‘0x0000000000000…’ which tells us Player One got removed from the players[] array (because when I tested, Player One won. It may be Player Two for you). OK, the code works, but the change suggested above might prevent this if we feel it’s an issue.

As we have clause in draw() that won’t allow us to send any ETH balance off to the charity address until winners.length == 2 we need another player to win. As it happens, we can just hit draw() again and watch our remaining player win.

Re-draw and Contract Payout
Go ahead and hit draw() for a second time, then refresh the Etherscan page for your contract. You’ll eventually see a new 0 ETH transaction for the second draw and the contract value is now 0 ETH. That proves the charity.transfer(address(this).balance); line in draw() must have worked – but where’s the transaction?

End of the Test Run

You’ll notice there’s a new tab in Etherscan called ‘Internal Txns’, our `transfer` of 0.2 ETH is recorded in there as it occurs as part of the code in the function, not a call from outside. The balance is sent to the address that was defined under the `charity` variable.

Transfer of balance to contract owner

We’ve seen that at every step of the way we can control how the contract is deployed, deploy it to a non-live blockchain such as the Ropsten Testnet, then carefully test out the contract functionality. Remix and Etherscan combined provide us with a host of features and information to allow us to test our code and check the results.

There are more tests we could add, but the core features have been checked here. We’ve also discovered there are some (expected) weaknesses in the code that could be fixed up. Overall, a good couple of tutorials and a great way to learn more about Solidity and Smart Contract development.

Until next time!

1) Tutorials: and 2) Brave Browser:

Tuesday, 2 July 2019

Blockchain - Books on the Ethereum Blockchain

This article is also available on the blockchain at Kauri (Ropsten Testnet).
Taking book publishing onto the Blockchain is the idea of the Publica project. However, since the ICO in November 2017, and like many blockchain oriented projects attempting to shake up traditional spaces and come out of the late 2017 crypto crash, it’s a project that launched well, is backed by knowledgeable and capable staff - but that hasn’t been as successful as a more traditional approach might have been. That said, the ‘traditional’ nature of book publishing has been in the process of a complete shakeup for many years, so adding in a blockchain solution was a natural and logical next step.
In the indie book publishing space there are now many alternatives to getting your book into brick-and-mortar shops, usually filled by publishers who were once the only pathway to authorial success. Today, tens of thousands of books are self-published by their authors every year, without ever coming near the traditional publishing houses. Books that cover a multitude of genres from fantasy, spy, thriller, adult, young adult, teen, cooking, car mechanics, computing and business to name a few. While high street shops like Barnes & Noble or Waterstones might be suffering, the market for books, particularly eBooks, has never been bigger. Whether readers are buying from the likes of Amazon or direct from an indie author - book sales are buoyant, despite the doom and gloom around book sales we often read about. In 2017, when Publica launched, the global publishing industry was estimated to be worth $261bn USD. Of this, books accounted for 46% or $121bn USD(1). Not an insignificant market to chase even single digits percentage share of.

Publica Book Catalogue

Enter Publica – ‘Blockchain for Publishing’, as the site tells us. Publica offers two routes to publishing; a book ICO for funding new publications or direct publishing of already completed manuscripts. There’s a page on Medium that Publica keep up to date with the current Book ICOs(2) so they can be learned about and contributed to. There’s an online store(3) and a mobile app(4) where users can access the store of available books, the reader’s own library of owned works and the wallet in which the Pebble tokens are held. Imagine the Kindle or Apple Books store, with an appropriate reader with built in shop that also shows your balance of funds. That’s what Publica have – same idea, just using crypto and blockchain.

At the time of the ICO, which ran from November 1st to 15th in 2017, Publica raised $1.04m USD(5) and have regularly stated in their various Telegram channels that the project’s success is not predicated on funding, which is good to hear. So, what’s preventing the project from seeing the success that was hoped for? Two things: it’s a cutting-edge solution that takes time to achieve adoption and secondly, it’s not in any way as straightforward to get started as buying a physical book or firing up your Kindle or other eReader. That said, eReaders were a strange phenomenon at one point but we all got used to them too, so there’s hope for Publica.
Publica is for the author who wants to regain control of their work, business and writing career. They will control exactly how their audience enjoys their content. There are no rules from Publica. The rules are just between you and your readers. - Josef Marc, CEO
Ethereum Blockchain, ETH, Pebble, BOOK tokens and Book ICO Contracts
The Publica solution is deployed on the Ethereum blockchain, which makes issuing the Pebble (PBL) ERC20 compliant token and the BOOK non-fungible token (NFT) the easy part. It also means authors and readers can interact with the underlying smart contracts using convenient tools such as a browser and MetaMask.

PBL’s are the fungible token that act as the internal currency for Publica. All books are priced in PBL and the tokens can be bought and sold on various exchanges and swap services for ETH or using a credit card.

BOOK tokens are the interesting one; every book that you buy is actually acquired by purchasing a BOOK token. This represents the tokenisation of the book. You pay PBL for the BOOK tokenised asset and get that in your Publica library. Think of it as an access key to a copy of the book you own that’s stored on the blockchain.

For each Book ICO, Publica deploy a smart contract that has the unique details of your book ICO. That includes obvious things such as the title, but also details of hard and soft cap, the number of PBLs you want to sell each BOOK token for and so on. This is interesting as it’s a potential bottleneck to growth due to it being a manual process.

Running a Book ICO
The entry point that Publica seem to promote most actively via their website(6) is the funding of book writing and creation by running a Book ICO. This is a novel idea, akin to running a Kickstarter project to get funding in advance of working on whatever the project is about. Authors are required to provide details for a book ICO page and then get promoting it in order for potential readers to find the page, buy some PBL to buy a BOOK token, then await the ICO ending and the book being written.

Buying a Published Book
When a published book is added to the Publica library, a reader simply has to view the library via the mobile app or online store, find a book they like and purchase it using PBL tokens stored in their connected wallet or due to a recent change, they can now pay with their credit card.

Screenshots from the Publica App

Benefits over Traditional Publishing
Two major benefits that are gained by using Publica are that authors acquire Borderless Publishing and Censorship Resistance. Never again can a book be banned from a given country and the contents of that book cannot be altered once published. Not even by Publica - this is a paradigm shift. Let's get this clear - never in human history has this been the case and could fundamentally shift the way publishing works.

There is a caveat to the process of getting a completed book published – it’s entirely manual. You fill in a form, send it to an admin (the amazing, hardworking Alex!), they create a contract and deploy it. All manual. If Publica ever had hundreds of authors hit them, they’d be backlogged overnight. Though I suspect they'd love the challenge. The Book ICO is also a manually created campaign and manually written and deployed contract. Neither have been an issue so far, the team are pretty efficient and accurate, but growth could see this needing to be addressed.

Benefits over Typical eBook Publishing
Once often overlooked issue with buying eBooks on say the Kindle, is you don’t actually own them. What you are granted is the right to host a copy of the book on your device and retain it in a library you can access. Amazon can, and have, deleted access to the books from people’s devices. Not so with Publica. No one can delete the data on the blockchain. Once you buy it, you own it.

What’s slowing the Publica project?
In short, adoption by new users. In both cases, the work on deciphering the path-way to buying books, via an ICO or straight from the Shop, is definitely pushed to the buyer – and that work required to get going with Publica, besides the relative newness of blockchain that also needs to be understood, is above all else slowing the project’s growth. Sure they have good FAQs, but it’s a big hurdle the likes of Amazon didn’t put in front of their own Kindle device and store. 

Before they even get to Publica, the potential readers have to learn about the blockchain first. They need to understand what Ethereum and Pebble are, how to use crypto exchanges to get the PBL tokens into a wallet, how to use that wallet and what buying a BOOK, as an NFT version of the eBook they want entails, the pros and the cons. Once that’s out of the way the App or online shop is no more complex than hitting the Google Play store, Kindle eBook Store or Apple’s Book store on an appropriate device. Still, imagining a flood of new customers that would joyously surmount that first part was a bit optimistic by the project team, to say the least.

The move to accepting card payments was both a needed change, to ease adoption by the general public, but also a great way to just get people buying books and become familiar with Publica. Grab the app, search the store, buy your books. Done. However, that raises the question of what the point of the internal PBL token is now?

The Trials and Future Purpose of PBL
Pebbles or PBLs, have been through a rocky time. They were intended as the internal currency for making BOOK token purchases, rewarding authors and something that the investors in Publica, via buying of the PBL, could be rewarded through as Publica became more successful.

Since 2017, PBL have gone down from an ICO price of $0.10 to a current average price of $0.0188. Trading volumes have hit the floor as current holders HODL, potential investors look for something more active to invest in and Publica readers switch to using their credit cards. Being able to buy BOOK tokens directly via fiat is great news for readers and authors, but bad news for PBL holders already stung by the decline in value since the ICO.

To add to this, finding a place to trade PBL has also proven difficult, since PBLs were delisted off KuCoin, the main exchange used since PBLs became available. Currently, the best place to find PBLs appears to be ForkDelta or Bilaxy(7) where there is low trading volume but a high amount of tokens that can be bought quite cheaply. Why they are needed now still remains a question. Investment? Perhaps. Funding the project? Possibly. Central to making the project work technically? Apparently, not anymore. PBL is still used to calculate the internal price for BOOKS and the total cost of purchase, i.e. including gas, transaction fees, etc., and if you sell a BOOK token on the Publica secondary market you’ll get PBL back, so you want it to be worth something.

Only one possible idea comes to mind for investment; HODL a large enough amount of PBL that when Publica is bought out by someone like Amazon, then PBL shoots up in value and you can cash in. That’s not trading advice though so DYOH. Right now, it looks like PBL could be dropped altogether, but we’ll see. Not reassuring for those HODLing since 2017, but as the saying roughly goes; the pioneers get the arrows, the settlers the spoils.

The Publica project is a great example of a meaningful use case being applied to the use of blockchain. It’s meaningful because resolving issues such as censorship, borderless publishing and permanent ownership are serious issues that need addressing. A database of books controlled from the centre, by a company beholden to worldwide legal systems isn’t the answer. Could Publica rise to the challenge?

Publica has it's strengths, but also some significant weaknesses that thankfully are being addressed. More books need to be published directly, ideally by known authors. Landing a deal with a known publishing house or a store such as Barnes & Noble or Waterstones would be an incredible boost. As for Book ICOs – they should be left on the backburner for now, they are rarely successful, so not the way to build the Publica Store of books in the short term. Holding PBL seems an uncertain prospect at this time as, beyond being a means for fundraising at the ICO stage and as a means for internal accounting, there’s no real need for them. That said, they could also be the one that 'moons' once he project really gets going.

Overall, it’s early days for this exciting project, but there’s uncertainty as to when it will see the growth many feel it deserves and when the traditional model of self-publishing can be replaced with the help of the blockchain. Could Publica be the next Amazon or arm of Google. It's a possibility, better still they might just become the Publica they want to be, now that would be something to be part of.


References: 1. 2. Book ICO List: 3. Book Shop: 4. Mobile App: 5. Publica ICO: 6. Publica Website: 7. ForkDelta:!/trade/PBL-ETH. Bilaxy:

I published my debut novel, The Hannover Game, on Publica.

Tuesday, 12 June 2018

Contracting - Let's Talk Money


It's why we do contracting, heck it's why we go to work. I've never understood the shyness we have in the UK about talking about money. Never ask anyone what they earn, how much they have saved, how their pension is going. I get it in the main.

We all struggle day to day just to pay the bills on time every time, pay the mortgage off (a dream for many), have a holiday once in a while and hey maybe even save up towards a pension. Not that anyone is going to retire in the future... It narks me that pulling together even a modest amount is such hard work, even when contracting. The 7-year cycle hits and knocks you down a few pegs. Tough but again, it's part of why we do contracting. To gain an accelerated income and make a better financial life for ourselves and our families.

But how much do YOU make?
To answer the question, £400 to £600 per day on average. That's been my contracting rate for pretty much the entirety of my contracting. I wonder if anyone reading this who knows me is surprised by that. I'd take £400/d  for a sit-in-the-corner doing coding stuff and towards £600 for a management role. There's been higher, but they were outliers.

Now, even though £400/d may seem low for someone with 20+ years of experience, it's still a truck tonne of money. So many contractors lose sight of that. 12 months of 20 days is 240 days, that times £400 is £96,000. That's nothing to complain about. A more typical minimum rate is £450/d, that's £108,000. Even if you don't bill all the days, due to holidays or gaps in contracts, you're still earning a shed load of money (running out of these now...)

Here's a reference to put that in context: (accessed today)

Average UK salary: £27,271

Before you start celebrating/consoling yourself, this data was taken by the Office For National Statistics from 21,563,000 people's earnings, with averages broken down for each profession. Topping the charts were brokers, who earned £133,677 on average, followed by chief executives and senior officials (£107,703), aircraft pilotsand flight engineers (£90,146) and marketing and sales directors (£82,962). At the other end of the scale are retail assistants (£10,296), hairdressers and barbers (£10,019), cleaners (£7,919), waitresses (£7,554) and bar staff (£7,404).
Even on the minimum of £450/d you're better paid than just about anyone. OK, no Million ££ bonuses for you but still something to pat yourself on the back for.

But can you manage it?
Gfeat, so you can pull in the revenue, but can you manage it? Let's loop back to the hands-on stuff.

The good stuff! Invoicing is pretty easy. Invoice your client as soon as you can each week or month, whatever has been agreed. Each invoice MUST have a unique ID. I have it as company-month-year-number, so ClientRef-Jan-18-001 for example. Calculate your charge (day rate x days worked) and add VAT @ 20%. Terms of payment are 28 days max, ALWAYS see if you can do weekly or fortnightly invoicing. You have nothing to lose but cash flow by asking!

When you do your monthly accounts, you need to record invoices sent out and paid to you, with the unique invoice number. Guess what? When you send an invoice you become liable for the VAT component even though you don't have the money yet. Yep, HMRC suck. So keep a buffer for covering that month's VAT in your business account.

Managing VAT
As mentioned, if you are on Standard Rate (20%) you can offset paid-out against collected VAT. Put anything that is remotely business like through the business and claim the VAT back.

Expense it!
Above almost anything, managing your expenses and reducing your tax is THE single most important reason you're doing this. It *can* seem like a lot of work, but the cumulative savings are worth it.
Electronics, equipment, computers, stationary, postage, books, subscriptions, training, software, hardware, ink, paper, printing, mobile phone (1 per employee), desks, shelves, pot plants (no, not that type ;p), cables, travel, subsistence - ANYTHING that could be stated as business related.

The above is a fine art, but there's more that can go through the business than you might think. The thing to bear in mind is - who can say what was really a legitimate expense? (caveats below) Do you think Coca Cola Corp don't put through crap like pencils, that odd subscription to the gaming magazine (hey, marketing research, new business idea) or say a training course to increase employee capability? Expense it, but be mindful of WHY.

You'll be able to calculate each month how much of that invoice amount you can take as Dividends/Salary. (Invoice amount, minus the VAT, less corporation tax) Let's say it's 8k. Remember that when you expense the above you're paying for it out of that potential 8k - so it's your money your taking, just that as you take it via expenses a) the company reduces it's overall profit and so the tax it pays, and b) you reduce the amount of Dividends you can take (Dividends can only come from corporation taxable profit that's left after expenses). So, if you expense 1k - the company only has profit that month of 7k so pays less Corp Tax at the end of the year. Of course now you can only take 7k dividends and so pay tax on that reduced amount. Also, if what you spend that 1k on is VAT'able, then you offset that outgoing VAT against the incoming VAT, saving that too.

Replay this - by spending on 'expense' through the business, you just saved the Corporation and Personal tax on that 1k and offset the VAT. Think the other way. You take the full 8k, having paid Corporation tax and personal tax, then buy something you pay VAT on. You just got taxed three times (VAT, Corp tax, personal tax), where you could have avoided it all. That is a powerful way to get a LOT more buying power for your money.

A note on expenses: As mentioned above, you can expense 1 mobile bill per employee (i.e. you.) but oddly also a £150 a year on a Christmas dinner per employee, the dinner is tax free like any other expense. However - note that Corporate Hospitality (lunches for clients, etc.) is classed as spending taxable profit. Get it? You pay £10 on dinner, at the end of the year HMRC say that money is part of the overall profit and you pay Corp tax on it. Odd but true.

Check the current figure but generally any item over £1k has to be amortised over a number of years. For example, buy a £3k computer and you can declare £1k as an expense now (Corp tax free), but the other £2k gets taxed. Next year you write-down the asset by £1k, saving the tax as this is a loss on profit. Same again next year. So you DO save the tax, just not in the same year.

Recapping - Expense it
Let me touch on this again. I'm always shocked how small minded fellow business owners are about what they put through their business. HMRC rule is that whatever goes through the business has to be a legitimate business expense. If you're going to reduce profits and so the tax paid, it has to be on something for the business.

So no, a night out at the cinema isn't a tax deductible, legitimate expense. Nor is that shiny new suit or fancy jacket you've been looking to buy. But it's a fine line. If that suit is a uniform, perhaps with a tailored company logo then it's got a unique use for the business and is a valid expense. If that cinema trip is corporate entertainment it can go through the books, but remember you pay tax on it so HMRC aren't going to panic.

If in doubt, leave it out. Or something like that. You know how I keep going on about not getting on the tax man's radar, this is a good example. Again, I've seen fellow business owners do all sorts of stupid things - just don't. Will a small business like us get queried? Probably not, but if you do then everything is up for investigation. You don't need that in your life.

In closing
Check every year what is and isn't the case with the above. Figures, allowable items, etc. change all the time. However, I hope the above has given you a sense that as you run a business now, you need to shift your mindset to that of a business owner. Be bold!

Until next time,

BTW... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.


Contracting - Business Set-up Steps, Admin, How and Why

From my previous post on the subject I gave a general overview of getting set-up as a business. Here's some more specific detail. Though this applies to the UK, I think the principles are the same.

Set up the Limited Company
Either do this through Companies House or via a company that does this for you. I recommend doing this with a company who deal with everything. It costs a bit more but is hassle free. Registration and set-up takes about 2 weeks.

You'll need a company address, Director and Secretary (who can be the same people). Be aware the company address is public so you might want a virtual office address. You will get a Registration Certificate with the company name and registration number on it. You'll need these later.
When you set up the business make sure you sign-up for Online Filing (if it's even an option NOT to now, I think it's mandatory) and ID Protection so no fecker can change your company details on the sly.


Register for VAT
You can ether register for Flat Rate or Standard Rate. You need to do this via the 'Government Gateway' services on the Companies House website. It takes about 1 week to get registered and you'll be issued Gateway ID, Pass, etc. and a VAT Certificate. As with the company registration certificate scan it and keep it safe as you will need this all the time too.

If you use Flat Rate (14%) you can charge your clients 20% and pocket the other 6%. I've never done this and having an overriding moral compass that doesn't let me skim like this I don't approve. That said, I know several contractors that do it. The other benefit is you don't need to calculate VAT paid out because you can't claim it back. That's the trade-off for using Flat rate.

Personally, I have always been Standard Rate, so that I can charge and offset VAT. Through the year any VAT paid is taken away from VAT collected on invoices and the difference paid to HMRC. If you buy anything business related, goods or services then offset the VAT. Never screw your VAT up - more on that later.

Company Bank Account
You MUST have a company account as business money/transactions must not be done through a personal account, ever. I use Santander as there were no fees, but some people don't like them as customer service can be pretty bad.

I've had no problem with them so far. Register online, it takes about 2 weeks to get set up. You'll get online banking, company paying in book and cheque. File them away, I bet you never use them given you have online access.

Take a note of your company account number, sort and IBAN (International Bank Account Number) as you'll need these later for clients to pay you.

Never, ever, ever, .... take out any money that is VAT or business/ corporation tax. You *can* as a director loan, but do it even once and HMRC will have their eye on you. I've also seen this being a deep hole you can get into as you try and pay VAT and Corp tax on time. More on that later.

Get Insurance
You'll need Liability Insurance as a minimum. That's the insurance you lean on when a client says you screwed up and need to pay back fees plus damages.  You might also need Public Liability insurance and Employee Liability Insurance, but not at first.

I use Simply Business brokers, check them out to get an idea: Simply Business

Appoint an Accountant
You'll need to do Book Keeping and Accounts when running your business. My recommendation is don't even think about skimping on an Accountant service. I use SJD Accountants and the advice they give you will save the fee they charge and the same again. What's more they're a source of ongoing advise on tax thresholds, VAT and other HMRC related goodness. Add to that, even if you do your own books and draw up your own accounts you still need them certified by an accountant before passing to HMRC. So don't bother; keep your books and pay for an accountant. As at June 2018 SJD is £140 a month including VAT (which you off-set of course) which is cheap.

All Set Up

At this point you have an incorporated business, that's VAT registered, insured, operating with a bank accountant and an appointed accountant. Yay! Now all you need is clients ;]

Doing your books
Do your books monthly and sweat over the small things. Your accountant will want them quarterly (see below) but do them monthly. You ARE going to want to record accurate details of every transaction no matter how big or small, there is no other correct way of doing this. Every fricken penny. You don't get frustrated with the tedious detail, you will never think 'It'll be ok' or ' I'll just square it off by doing this...'. Get it right 100%. I've seen sloppy accounts from other contractors too many times and it's scary. This will be hard and concerning at first, but after the first year it gets pretty routine.

A month of books will take you an evening. So 3 months of books will take you nearly a week…wait what? It will take longer because you'll have to remember what that odd receipt was, you'll forget an invoice or won’t find it, etc. Do your books monthly. OK, lecture over!

Quarterly Submissions (VAT)
Every 3 months your accountant will want your books (your accounts) sent in for review by a certain date. They will look over VAT figures, dividends and salary paid to date, etc. and send you a VAT Return along with any advice on whether you're paying yourself too much salary and dividends.

Your quarterly VAT Return is a CALL TO ACTION, jump on it! There are two components, the return you must go to the HMRC site to fill in (remember when you registered for VAT?) and the VAT payment. The SAME DAY you get your VAT return details from the accountant, do the return online and pay the goddam VAT.

The return is no more than about 10 fields, already filled in by the accountant, that you fill in online and hit submit. If you miss the return date you WILL be on HMRC radar. So just do it and pay the VAT that day, it's a 10 minute job.

Annual Accounts
At the end of the year, the accountant will pull together the formal accounts for the year. You'll get a Full and Abbreviated set, not much difference at our scale to be honest. However, they will ask you to review and confirm they can do the submission, review and then let them. HMRC trust verified accounts more than you or some mate sending them in. You also need to have your business bank accounts statement for the year sent along with the accounts to HMRC. Yup, glad you have a neat Business account now right, even if it is a legal requirement ;p

The accountant will assess how much Corporation Tax you have to pay. Oddly, end of year accounts are in the April/May timeline, but Corp Tax isn't due until January (usually, your accountant will advise as it depends on if you changed your 'filing date' (hint: don't). I have no idea why the delay, who cares. As with VAT, once you know the figure and can pay it (and you can because the money was always in the bank right?..) - just pay it.

Note on VAT and Corp Tax Payments: You pay both via an online transaction from your business account, to a HMRC account that is given online in the VAT / Corp Tax areas of the Gateway services section of the HMRC website. Your accountant will also know these details. However, you only need to go online and submit a return for VAT. Your accountant submits your end of year accounts and HMRC advise on the Corp Tax owed.

Annual Return
At the end of the year you also need to do an Annual Return. That is an online document where you state Directors, Company Secretary, Paid up Shares, Classification of Business, Confirm Address, etc. If nothing changes in the year you can skip through, make the Return, pay your £15 and you're done. Again, a 10 minute job. Just think of this like a Companies House business listing. Literally just admin for HMRC records.

Annual Directors Tax Return
As a Director you WILL have to do an annual tax return, where as an employee you might be asked some years. There's a bit more detail needed like investments, dividend, account interest. It's tedious as crap but most comes from your bank and business accounts. Your accountant will advise you of the need to fill this in and set you a deadline. I find it takes a couple of evenings to pull the details together (trawling bank accounts to find you made 14p interest in the year is so much fun). Fill it in, send it back to you accountant and authorise them to submit.

Paying your Personal Tax Bill
A few months after sending in your personal tax return, usually January like Corp Tax, you get a personal tax bill. This is your tax bill for taking salary and dividends. As always - get the bill pay the bill - ASAP. Unlike VAT and Corp Tax, personal tax must be paid from a personal bank account, as
it's your bill not the company's. But no sweat - because every time you take dividends, you should set aside the personal tax you'll pay on them. Then at the end of the year just pay it to HMRC. Like VAT and Corp Tax, this was money that was never yours, so no biggy. Hive it off each month and stick it into a separate account. If you have a personal account you never use, then great, use that.


So now; every month you do your books to keep track. You take your dividends and hive off your personal tax. Each quarter you do a VAT return and pay the VAT balance. Each year you do Annual accounts to calculate Corp Tax and pay it ASAP. You do your Personal Tax Return to calculate your personal tax and pay it ASAP. You then do your Annual Return to give admin details to HMRC.

And that's the business and HMRC formalities. Sounds a lot, but actually it gets pretty routine.

Next, let's talk about actual money management.


I copied this image off the Companies House Website...

Monday, 11 June 2018

Contracting - Entrepreneurship

Entrepreneurship - what is it?

Setting aside the obvious quip about how ridiculous this word is to spell... welcome to English (French...).

In my view it's as mentioned in the prior post. Looking at your world in an entirely different way. No longer are you being led but you're leading, no longer do you just have a job, you have a profession, no longer do you just work for The Man and nod your head in all the right places, you have to think.

I was heard a sermon by an American pastor, can't remember who sorry; the idea was to ask not for a miracle but a thought, an idea. That you were just one idea away from changing the world, one thought away from being a millionaire. In my opinion, entrepreneurship is just that. It's the generation and then execution of ideas and thoughts.

As an entrepreneur your job is to *think*, to think about what can make you money, that's thinking about who your customers are, what your customer wants and that you can provide, thinking about how you will provide it, for what price, in what way and of course, when. Then bill them for it.

I said before, opening your own business, seemingly just to go IT contracting at first, will open your mind to the possibility that everything you do is now a possibility to turn a profit. Everything you do is 'business'. It may be for a large profit or a small one, but it's business for a profit.

You HAVE to make a profit
The good thing is (at least in the UK), as a Director of your own business you can direct the business to engage in whatever will turn a profit. Did you know you have a legal responsibility to make a profit? That's right Mr, Mrs, Miss, Miz, He, She, Zee, It Director, you have to keep a grip of your business, think of clever ideas and make sure your new company makes a profit.

You may well start your business with the simple idea of increasing your personal income from that of your normal wage. It's true, that for the majority of people, going contracting will help you realise an increase in the amount of cash you take home. Remembering never to get tempted by any scheme that claims you can take home even more than that of a combined dividend and salary payment. However, I'm sure that once you start delivering your IT work under an independent contract, you'll figure out related ways to make a little extra cash contracting, through diversification.

There's never been a better time to make an independent income. Despite how much HMRC are clamping down on IT contractors, to the point I think they'd like to see the whole model disappear, you can still make a good income. The tricks are as stated in the first post and diversification. No one can tell you what your business can or can't engage in, what is a legitimate area of research, trading or down right experimentation.

Your Business is your Business
If you decide your business not only delivers testing services but also coding, writing technical articles, mentoring, developing video games, researching the latest tech or just blogging crazy IT ideas - then good for you. That's Entrepreneurship with a capital E and what the country needs. Expenses and profits related to these are all legitimate. Claim those R&D Tax Credits too. Fill out your accounts and submit with confidence.

I've seen too many people limit themselves in thinking their business is *just* testing or coding. Yet, then work with other companies who provide a range of services. So can you. Do whatever it takes to make a profit. Be a true entrepreneur, be enterprising, creative and thoughtful. It doesn't cost you any more to think than not think.


PS... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.

Contracting - Thoughts on getting set-up

Independent IT Contracting is a mixed experience. Some of it is good for sure, some of it is just a grind but you can get on with it and other bits are definitely a pain in the ass.

The Good
One great aspect that I never expected from going contracting was the sense of becoming an entrepreneur. Once I set up my own business (Ltd company via Companies House in the UK), it was a fundamental shift in mindset. Like others I'd spoken to, I was struck with the idea that I had full control over my financial destiny. That my time and effort, focus and interests were all now a way to generate revenue and in turn generate a profit. Every £$€ earned and spent was relevant.

No more coasting from pay cheque to pay cheque with the hope of a small percent pay rise each year and possible bonus. No more just paying the bills and tick-tocking along between pay day, bills and whatever saving I could make until retirement. Now it was all to play for. Win or Lose, it was down to me.

The Bad
Along with registering a business of course came some other administrative burdens. Registering for VAT, getting business insurance, hiring an accountant, keeping the books and doing quarterly accounts, annual returns and tax declarations. Sounds like a burden and hey, it's not exactly exciting, but it keeps you in touch with what is really happening in the business. This is absolutely key.

A few things I learned from hard won experience regarding these points:

  • Never miss any filing dates for HMRC, ever
You can be late paying your VAT or Business Tax, but file late and you'll be fined. You'll also be on the taxman's radar - and you definitely want to stay off that! Get your filings done on time every time.

  • Get an accountant to do your end of year accounts
As above, you need to make sure everything you put through the business is a legitimate expense, every invoice to clients, every payment into the business and every aspect of your financial accounts is spot on. Then wrap all of this up in a set of reviewed and approved accounts that get sent onto HMRC. That way there's no concern you made stuff up or made mistakes. Keep HMRC happy and off your back or it's yet more admin for you to do.

  • Never, ever use any umbrella, loan scheme, 90% income scheme or similar
Just avoid these like the plague. Yes, even umbrella companies. The simple reason is you lose control of what your income 'means'. It has to mean income - revenue from invoices, minus expenses for running the business (costs, tax, etc.), which leaves you profit from which to pay yourself director's dividends and salary. That's it no confusion, no sudden discovery HMRC don't like the scheme you're using, no accusation it's a tax avoidance scheme or even worse, outright tax evasion.

  • Do avoid paying as much tax as possible, legally
You have an absolute responsibility as a director of a business to save all costs and maximise all profits for the business, in any legal way possible. This is your new responsibility and you must be focused on it. Stop thinking like a salary slave and start thinking like an entrepreneur. Having your own business affords you so many opportunities in this regard you'll save literally thousands per year that non-business owners cannot save.

The Ugly
If you want to keep earning in IT contracting - you must keep learning. If you don't like the idea of being a lifelong learner, this may not be for you.

If you don't keep learning what's new in the marketplace, what is being asked for in contract job postings and what are the emerging practices or technologies - you're going to be un-hirable sooner than you think.  Almost every single time I got into a contract I watched as the world moved on outside of the domain I was working in, which meant I had to sit courses, watch YouTube videos and do hands on practice just to keep up to speed. Even with my ability and focus on this, I still got behind. You cannot sit on your laurels when contracting.

Until next time.


Friday, 8 June 2018

Goodbye Contracting, Hello...

In a series of short posts I've decided to 'come clean' about the last 10 years of contracting. Sharing some insights I don't often see are shared by other contractors and opening up about things I've not been able to talk about. I hope you enjoy these warts and all posts. They've been a long time coming.

A New Direction
Just over 10 years ago I started my own small consultancy and went feet-first into contracting. At the time I was working for BJSS, a great consultancy with an amazing team. Leaving was a hard choice and one that would play on my mind to the present day. More on that later.

My very first contract was as a Test Manager on a Government Gateway project. I still have the fleece they gave us to celebrate the successful launch. I remember being a bit irked by one of the team who would constantly text on their phone during the stand-up. I literally wanted to shout at him to get out of the room, but hey, first contract and all that so I behaved!

Doable, but not Plane Sailing
To anyone that's thinking of becoming a contractor and nervous about whether they will fit in, be able to deliver, be able to handle the pace and focus - I say go for it. You can always decide it's not for you and go back to working for the Man. There is a lot of set-up and things to learn, but it's a great mind-shift. More on that later too.

Along the way I've had some great engagements, with real kick-ass deliveries that have left the client's business and team changed for the good. There's also been a good number of glitches along the way too. Yes, some clients are a nightmare. Either because they pay late, demand the unreasonable or just decide you're making them look bad. While I won't name names, it's time to share those stories too.

Things Change
A lot has changed since those early days, both in terms of the contract market, the way the UK government deal with contractors and how I find and deliver work.

It's no secret the UK government, via HMRC (like the IRS), are absolutely hammering contractors. From the introduction of IR35 legislation, cracking down on Umbrella companies and Loan schemes to reducing allowable expenses and increasing the tax paid on dividends - to name just a few moves against contractors in the last few years. Despite all this, contracting remains viable if you have the skills and contacts to make it work. I'll share how some of these things have hit me personally and how I responded to them.

The Secret Sauce to Contracting
If I had to distil what the keys to success have been, I'd say the following:
  • Always, always respect your customer and over deliver in any way you can
  • Every single day learn something new, keep developing your skills
  • Build your network, it's where 90% of your contracts will come from
  • Never, ever get on the wrong side of or try to fiddle the tax man
I'll see what insights I can share around these.

Until next time,


PS... see that Mark J Diez, Hannover Game ad at the top right? That's me, I wrote that.
Click it and buy a copy.

Wednesday, 8 March 2017

100 Day Deep Work - Day 6: Checking Multiple Links using WebDriver

Here we are, Day 6 and pretty much a continuation of yesterday. I suppose I should say refinement or refactoring. Compared to the approach taken in yesterday’s session I scaled this right back to something simpler. Why? Here comes today’s (and yesterday’s) real learning.

I was breaking the golden rule of taking it one step at a time. Instead I was trying to work out what the overall solution looked like then code it up. That was doomed to failure so I went back to baby steps and simplified things.

First off, recall the (cut down) testing problem from yesterday:
You have a website with 2 navigation links. The expectation is more links will be added in the future. The test must check the known set of text links are present and if any new ones have been added.

That’s the first part so let’s work out some code for that.

Here’s the list of expected links:

public enum links

We need to a) locate the links section and b) count how many links there are on the page:

var locateTheLinkSection = 

var actuaLinkSetCount = locateTheLinkSection.FindElements(By.TagName("a")).Count();

Good, we have a count of what is on the page, but is that what was expected?

var expectedLinkSetCount = links.Count();

Console.WriteLine($"Expected link Set Count is {expectedLinkSetCount}.");
Console.WriteLine($"Actual link count is: {actuaLinkSetCount}");

We could wrap this in an if-else or a try-catch to actually DO something given the outcome, but that’s a way to get our check done.

I’d still like to report what was new, what actual links got found, etc. not just a count - but that’s something to look at later.

Good, onto day 7!